feat(cli.rs): allow config argument to be a path to a JSON file (#2938)

This commit is contained in:
Lucas Fernandes Nogueira 2021-11-22 19:08:54 -03:00 committed by GitHub
parent 8b651b9e31
commit 7b81e5b82e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View File

@ -0,0 +1,5 @@
---
"cli.rs": patch
---
Allow `config` arg to be a path to a JSON file on the `dev` and `build` commands.

View File

@ -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
@ -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

View File

@ -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");
@ -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()
@ -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()