Skip to content

Commit 7b81e5b

Browse files
authored
feat(cli.rs): allow config argument to be a path to a JSON file (#2938)
1 parent 8b651b9 commit 7b81e5b

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

.changes/cli-config-path.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": patch
3+
---
4+
5+
Allow `config` arg to be a path to a JSON file on the `dev` and `build` commands.

tooling/cli.rs/src/cli.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ subcommands:
1515
- config:
1616
short: c
1717
long: config
18-
about: config JSON to merge with tauri.conf.json
18+
about: JSON string or path to JSON file to merge with tauri.conf.json
1919
takes_value: true
2020
- exit-on-panic:
2121
short: e
@@ -66,7 +66,7 @@ subcommands:
6666
- config:
6767
short: c
6868
long: config
69-
about: config JSON to merge with tauri.conf.json
69+
about: JSON string or path to JSON file to merge with tauri.conf.json
7070
takes_value: true
7171
- target:
7272
short: t

tooling/cli.rs/src/main.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ macro_rules! value_or_prompt {
5757
}};
5858
}
5959

60+
fn get_config(config: &str) -> Result<String> {
61+
if config.starts_with('{') {
62+
Ok(config.into())
63+
} else {
64+
std::fs::read_to_string(&config).map_err(Into::into)
65+
}
66+
}
67+
6068
fn plugin_command(matches: &ArgMatches) -> Result<()> {
6169
if let Some(matches) = matches.subcommand_matches("init") {
6270
let api = matches.is_present("api");
@@ -199,7 +207,7 @@ fn dev_command(matches: &ArgMatches) -> Result<()> {
199207
dev_runner = dev_runner.target(target.to_string());
200208
}
201209
if let Some(config) = config {
202-
dev_runner = dev_runner.config(config.to_string());
210+
dev_runner = dev_runner.config(get_config(config)?);
203211
}
204212

205213
dev_runner.run()
@@ -234,7 +242,7 @@ fn build_command(matches: &ArgMatches) -> Result<()> {
234242
build_runner = build_runner.bundles(bundles);
235243
}
236244
if let Some(config) = config {
237-
build_runner = build_runner.config(config.to_string());
245+
build_runner = build_runner.config(get_config(config)?);
238246
}
239247

240248
build_runner.run()

0 commit comments

Comments
 (0)