mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(cli): allow for toml and json5 files in --config arg (#13079)
This commit is contained in:
6
.changes/toml-json5-configs-in-cli.md
Normal file
6
.changes/toml-json5-configs-in-cli.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
tauri-cli: minor:enhance
|
||||
"@tauri-apps/cli": minor:enhance
|
||||
---
|
||||
|
||||
Add support for passing TOML and JSON5 config files to `--config` arg
|
||||
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -8537,6 +8537,7 @@ dependencies = [
|
||||
"insta",
|
||||
"itertools 0.13.0",
|
||||
"json-patch 3.0.1",
|
||||
"json5",
|
||||
"jsonrpsee",
|
||||
"jsonrpsee-client-transport",
|
||||
"jsonrpsee-core",
|
||||
|
||||
@@ -51,6 +51,7 @@ tauri-bundler = { version = "2.3.0", default-features = false, path = "../tauri-
|
||||
colored = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { version = "1", features = ["preserve_order"] }
|
||||
json5 = "0.4"
|
||||
notify = "8"
|
||||
notify-debouncer-full = "0.5"
|
||||
shared_child = "1"
|
||||
|
||||
@@ -45,7 +45,7 @@ pub struct Options {
|
||||
/// Skip the bundling step even if `bundle > active` is `true` in tauri config.
|
||||
#[clap(long)]
|
||||
pub no_bundle: bool,
|
||||
/// JSON strings or path to JSON files to merge with the default configuration file
|
||||
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
|
||||
///
|
||||
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
|
||||
///
|
||||
|
||||
@@ -60,7 +60,7 @@ pub struct Options {
|
||||
/// Space or comma separated list of bundles to package.
|
||||
#[clap(short, long, action = ArgAction::Append, num_args(0..), value_delimiter = ',')]
|
||||
pub bundles: Option<Vec<BundleFormat>>,
|
||||
/// JSON strings or path to JSON files to merge with the default configuration file
|
||||
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
|
||||
///
|
||||
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
|
||||
///
|
||||
|
||||
@@ -59,7 +59,7 @@ pub struct Options {
|
||||
/// Exit on panic
|
||||
#[clap(short, long)]
|
||||
pub exit_on_panic: bool,
|
||||
/// JSON strings or path to JSON files to merge with the default configuration file
|
||||
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
|
||||
///
|
||||
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
|
||||
///
|
||||
|
||||
@@ -63,10 +63,22 @@ impl FromStr for ConfigValue {
|
||||
} else {
|
||||
let path = PathBuf::from(config);
|
||||
if path.exists() {
|
||||
Ok(Self(serde_json::from_str(
|
||||
&read_to_string(&path)
|
||||
.with_context(|| format!("invalid configuration at file {config}"))?,
|
||||
)?))
|
||||
let raw = &read_to_string(&path)
|
||||
.with_context(|| format!("invalid configuration at file {config}"))?;
|
||||
match path.extension() {
|
||||
Some(ext) if ext == "toml" => Ok(Self(::toml::from_str(raw)?)),
|
||||
Some(ext) if ext == "json5" => Ok(Self(::json5::from_str(raw)?)),
|
||||
// treat all other extensions as json
|
||||
_ => Ok(Self(
|
||||
// from tauri-utils/src/config/parse.rs:
|
||||
// we also want to support **valid** json5 in the .json extension
|
||||
// if the json5 is not valid the serde_json error for regular json will be returned.
|
||||
match ::json5::from_str(raw) {
|
||||
Ok(json5) => json5,
|
||||
Err(_) => serde_json::from_str(raw)?,
|
||||
},
|
||||
)),
|
||||
}
|
||||
} else {
|
||||
anyhow::bail!("provided configuration path does not exist")
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ pub struct Options {
|
||||
/// List of cargo features to activate
|
||||
#[clap(short, long, action = ArgAction::Append, num_args(0..))]
|
||||
pub features: Option<Vec<String>>,
|
||||
/// JSON strings or path to JSON files to merge with the default configuration file
|
||||
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
|
||||
///
|
||||
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
|
||||
///
|
||||
|
||||
@@ -48,7 +48,7 @@ pub struct Options {
|
||||
/// Exit on panic
|
||||
#[clap(short, long)]
|
||||
exit_on_panic: bool,
|
||||
/// JSON strings or path to JSON files to merge with the default configuration file
|
||||
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
|
||||
///
|
||||
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
|
||||
///
|
||||
|
||||
@@ -60,7 +60,7 @@ pub struct Options {
|
||||
/// List of cargo features to activate
|
||||
#[clap(short, long, action = ArgAction::Append, num_args(0..))]
|
||||
pub features: Option<Vec<String>>,
|
||||
/// JSON strings or path to JSON files to merge with the default configuration file
|
||||
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
|
||||
///
|
||||
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
|
||||
///
|
||||
|
||||
@@ -54,7 +54,7 @@ pub struct Options {
|
||||
/// Exit on panic
|
||||
#[clap(short, long)]
|
||||
exit_on_panic: bool,
|
||||
/// JSON strings or path to JSON files to merge with the default configuration file
|
||||
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
|
||||
///
|
||||
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user