Skip to content

Commit a0a6a5a

Browse files
authored
Merge pull request #204 from choco-technologies/copilot/add-config-option-to-dmf-get
Add --config option to dmf-get for command-line configuration file specification
2 parents a6fb108 + 2214ada commit a0a6a5a

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

tools/system/dmf-get/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ dmf-get -o /path/to/output mymodule
5151

5252
# Specify tools name for variable substitution
5353
dmf-get -t arch/armv7/cortex-m7 mymodule
54+
55+
# Download module and copy configuration file
56+
dmf-get mymodule@1.0 --config board/config.ini --config-dir ./config
57+
58+
# Example: Download module with specific config (as requested in issue)
59+
dmf-get dmclk@0.4 --config board/stm32f746g-disco.ini --config-dir ./config
60+
61+
# Download with custom config destination name
62+
dmf-get mymodule --config mcu/default.ini --config-dir ./cfg --config-dest my.ini
5463
```
5564

5665
#### Multiple Modules with Dependencies File (.dmd)
@@ -97,11 +106,50 @@ dmf-man -d /path/to/docs mymodule
97106

98107
For more information about viewing documentation, see the [dmf-man tool documentation](../dmf-man/README.md).
99108

109+
#### Copying Configuration Files from Modules
110+
111+
When downloading a single module from the command line, you can specify a configuration file to copy from the module package using the `--config` option. This feature is similar to the configuration file support in `.dmd` files.
112+
113+
```bash
114+
# Copy a configuration file from the module to a destination directory
115+
dmf-get dmclk@0.4 --config board/stm32f746g-disco.ini --config-dir ./config
116+
117+
# This will:
118+
# 1. Download and install the dmclk@0.4 module
119+
# 2. Look for board/stm32f746g-disco.ini in the module's config directory
120+
# 3. Copy it to ./config/dmclk/stm32f746g-disco.ini
121+
122+
# Specify a custom destination filename (without module subdirectory)
123+
dmf-get mymodule --config mcu/default.ini --config-dir ./cfg --config-dest my.ini
124+
# Copies to: ./cfg/my.ini (instead of ./cfg/mymodule/default.ini)
125+
126+
# Use with variable substitution
127+
dmf-get mymodule --config boards/${BOARD}/config.ini --config-dir ./config -D BOARD=stm32f7
128+
# Substitutes ${BOARD} with stm32f7 in the config path
129+
```
130+
131+
**Configuration File Lookup:**
132+
1. The configuration file is searched in the module's config directory as specified in the `.dmr` file
133+
2. If not found in `.dmr`, the default location `<output-dir>/<module-name>/config/<config-path>` is used
134+
135+
**Destination Naming:**
136+
- **Default behavior**: Configuration file is copied to `<config-dir>/<module-name>/<filename>`
137+
- **With --config-dest**: Configuration file is copied to `<config-dir>/<custom-name>`
138+
139+
**Requirements:**
140+
- Both `--config` and `--config-dir` must be specified together
141+
- The module must be successfully installed before the configuration file is copied
142+
- If configuration file copying fails, the module installation still succeeds (with a warning)
143+
100144
### Command-Line Options
101145

102146
- `-d, --dependencies <path>` - Path or URL to dependencies (.dmd) file
103147
- `-m, --manifest <path>` - Path or URL to manifest file
104148
- `-o, --output-dir <path>` - Output directory for downloaded modules
149+
- `--config <path>` - Configuration file to copy from module (for single module only)
150+
- `--config-dir <path>` - Directory where configuration files should be copied
151+
- `--config-dest <name>` - Custom destination filename for configuration file
152+
- `-D, --define <VAR=value>` - Define variable for configuration path substitution
105153
- `-t, --tools-name <name>` - Tools name for variable substitution
106154
- `-a, --arch-name <name>` - Architecture name for variable substitution
107155
- `--type <dmf|dmfc>` - Prefer dmf or dmfc file type
@@ -166,6 +214,9 @@ dmf-get -t arch/armv7/cortex-m7 mymodule@1.0
166214
# Download to specific directory
167215
dmf-get -o ./my_modules mymodule
168216

217+
# Download module with configuration file (as requested in issue)
218+
dmf-get dmclk@0.4 --config board/stm32f746g-disco.ini --config-dir ./config
219+
169220
# Non-interactive mode (automatically accept licenses)
170221
dmf-get -y mymodule
171222
```

tools/system/dmf-get/main.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,8 @@ static void PrintUsage(const char* app_name) {
19271927
Dmod_Printf(" -m, --manifest <path> Path or URL to manifest file\n");
19281928
Dmod_Printf(" -o, --output-dir <path> Output directory for downloaded modules\n");
19291929
Dmod_Printf(" --config-dir <path> Directory where configuration files should be copied\n");
1930+
Dmod_Printf(" --config <path> Configuration file to copy (for single module only)\n");
1931+
Dmod_Printf(" --config-dest <name> Custom destination filename for config file\n");
19301932
Dmod_Printf(" -D, --define <VAR=value> Define variable for config path substitution\n");
19311933
Dmod_Printf(" -t, --tools-name <name> Tools name for variable substitution\n");
19321934
Dmod_Printf(" -a, --arch-name <name> Architecture name for variable substitution\n");
@@ -1963,6 +1965,8 @@ static void PrintUsage(const char* app_name) {
19631965
Dmod_Printf(" %s -d deps.dmd # Download all modules from deps.dmd\n", app_name);
19641966
Dmod_Printf(" %s -d deps.dmd --config-dir ./config # Download modules and copy configs to ./config\n", app_name);
19651967
Dmod_Printf(" %s -d deps.dmd --config-dir ./config -D BOARD=stm32f7 # Use variable substitution in config paths\n", app_name);
1968+
Dmod_Printf(" %s dmclk@0.4 --config board/stm32f746g-disco.ini --config-dir ./config # Download module with config\n", app_name);
1969+
Dmod_Printf(" %s mymodule --config mcu/config.ini --config-dir ./cfg --config-dest my.ini # Custom config destination\n", app_name);
19661970
Dmod_Printf(" %s -m http://... module # Use custom manifest\n", app_name);
19671971
Dmod_Printf(" %s --type dmfc module # Prefer dmfc files\n", app_name);
19681972
Dmod_Printf(" %s -a armv7-cortex-m7 module # Use arch name directly\n", app_name);
@@ -2332,6 +2336,8 @@ int main(int argc, char* argv[]) {
23322336
const char* manifest_path = NULL;
23332337
const char* output_dir = NULL;
23342338
const char* config_dir = NULL;
2339+
const char* config_file = NULL; // Configuration file to copy for single module
2340+
const char* config_dest_name = NULL; // Custom destination name for config file
23352341
const char* tools_name = NULL;
23362342
const char* arch_name = NULL;
23372343
const char* cpu_name = NULL;
@@ -2385,6 +2391,20 @@ int main(int argc, char* argv[]) {
23852391
}
23862392
config_dir = argv[i];
23872393
}
2394+
else if (strcmp(argv[i], "--config") == 0) {
2395+
if (++i >= argc) {
2396+
DMOD_LOG_ERROR("Error: %s requires an argument\n", argv[i-1]);
2397+
return 1;
2398+
}
2399+
config_file = argv[i];
2400+
}
2401+
else if (strcmp(argv[i], "--config-dest") == 0) {
2402+
if (++i >= argc) {
2403+
DMOD_LOG_ERROR("Error: %s requires an argument\n", argv[i-1]);
2404+
return 1;
2405+
}
2406+
config_dest_name = argv[i];
2407+
}
23882408
else if (strcmp(argv[i], "-D") == 0 || strcmp(argv[i], "--define") == 0) {
23892409
if (++i >= argc) {
23902410
DMOD_LOG_ERROR("Error: %s requires an argument\n", argv[i-1]);
@@ -2532,6 +2552,32 @@ int main(int argc, char* argv[]) {
25322552
return 1;
25332553
}
25342554

2555+
// Validate --config option usage
2556+
if (config_file) {
2557+
if (!config_dir) {
2558+
DMOD_LOG_ERROR("Error: --config requires --config-dir to be specified\n");
2559+
PrintUsage(argv[0]);
2560+
return 1;
2561+
}
2562+
if (dependencies_path) {
2563+
DMOD_LOG_ERROR("Error: --config cannot be used with -d/--dependencies\n");
2564+
DMOD_LOG_ERROR(" Use configuration syntax in .dmd file instead\n");
2565+
PrintUsage(argv[0]);
2566+
return 1;
2567+
}
2568+
if (command && (strcmp(command, "headers") == 0 || strcmp(command, "docs") == 0)) {
2569+
DMOD_LOG_ERROR("Error: --config cannot be used with %s command\n", command);
2570+
PrintUsage(argv[0]);
2571+
return 1;
2572+
}
2573+
}
2574+
2575+
if (config_dest_name && !config_file) {
2576+
DMOD_LOG_ERROR("Error: --config-dest requires --config to be specified\n");
2577+
PrintUsage(argv[0]);
2578+
return 1;
2579+
}
2580+
25352581
// Initialize curl
25362582
curl_global_init(CURL_GLOBAL_DEFAULT);
25372583

@@ -2930,6 +2976,12 @@ int main(int argc, char* argv[]) {
29302976

29312977
if (result != 0) {
29322978
counts.failed_count++;
2979+
} else if (config_file && config_dir) {
2980+
// If configuration file is specified via command line, copy it
2981+
DMOD_LOG_INFO("Configuration file specified: %s\n", config_file);
2982+
if (!CopyConfigurationFile(module_name, config_file, output_dir, config_dir, config_dest_name)) {
2983+
DMOD_LOG_WARN("Failed to copy configuration file (module was installed successfully)\n");
2984+
}
29332985
}
29342986

29352987
// Print installation summary

0 commit comments

Comments
 (0)