Skip to content

Commit

Permalink
feat(cli.rs): allow config argument to be a path to a JSON file (#2938)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Nov 22, 2021
1 parent 8b651b9 commit 7b81e5b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/cli-config-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cli.rs": patch
---

Allow `config` arg to be a path to a JSON file on the `dev` and `build` commands.
4 changes: 2 additions & 2 deletions tooling/cli.rs/src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ subcommands:
- config:
short: c
long: config
about: config JSON to merge with tauri.conf.json
about: JSON string or path to JSON file to merge with tauri.conf.json
takes_value: true
- exit-on-panic:
short: e
Expand Down Expand Up @@ -66,7 +66,7 @@ subcommands:
- config:
short: c
long: config
about: config JSON to merge with tauri.conf.json
about: JSON string or path to JSON file to merge with tauri.conf.json
takes_value: true
- target:
short: t
Expand Down
12 changes: 10 additions & 2 deletions tooling/cli.rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ macro_rules! value_or_prompt {
}};
}

fn get_config(config: &str) -> Result<String> {
if config.starts_with('{') {
Ok(config.into())
} else {
std::fs::read_to_string(&config).map_err(Into::into)
}
}

fn plugin_command(matches: &ArgMatches) -> Result<()> {
if let Some(matches) = matches.subcommand_matches("init") {
let api = matches.is_present("api");
Expand Down Expand Up @@ -199,7 +207,7 @@ fn dev_command(matches: &ArgMatches) -> Result<()> {
dev_runner = dev_runner.target(target.to_string());
}
if let Some(config) = config {
dev_runner = dev_runner.config(config.to_string());
dev_runner = dev_runner.config(get_config(config)?);
}

dev_runner.run()
Expand Down Expand Up @@ -234,7 +242,7 @@ fn build_command(matches: &ArgMatches) -> Result<()> {
build_runner = build_runner.bundles(bundles);
}
if let Some(config) = config {
build_runner = build_runner.config(config.to_string());
build_runner = build_runner.config(get_config(config)?);
}

build_runner.run()
Expand Down

0 comments on commit 7b81e5b

Please sign in to comment.