mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-07-14 19:10:28 +03:00
fix(cli): parse --profile=<profile>
syntax (#10135)
* fix(cli): parse `--profile=<profile>` syntax ref: https://github.com/tauri-apps/tauri/issues/6255#issuecomment-2192466839 * Update tooling/cli/src/interface/rust.rs * safe check next arg * add test --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
167b51a8de
commit
27838365a6
6
.changes/cli-profile-parse-syntax.md
Normal file
6
.changes/cli-profile-parse-syntax.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri-cli": "patch:bug"
|
||||
"@tauri-apps/cli": "patch:bug"
|
||||
---
|
||||
|
||||
Fix parsing of cargo profile when using `--profile=<profile>` syntax.
|
@ -1130,9 +1130,14 @@ pub fn get_profile(options: &Options) -> &str {
|
||||
options
|
||||
.args
|
||||
.iter()
|
||||
.position(|a| a == "--profile")
|
||||
.map(|i| options.args[i + 1].as_str())
|
||||
.unwrap_or_else(|| if options.debug { "debug" } else { "release" })
|
||||
.position(|a| a.starts_with("--profile"))
|
||||
.and_then(|i| {
|
||||
options.args[i]
|
||||
.split_once('=')
|
||||
.map(|(_, p)| Some(p))
|
||||
.unwrap_or_else(|| options.args.get(i + 1).map(|s| s.as_str()))
|
||||
})
|
||||
.unwrap_or(if options.debug { "dev" } else { "release" })
|
||||
}
|
||||
|
||||
pub fn get_profile_dir(options: &Options) -> &str {
|
||||
@ -1457,3 +1462,69 @@ mod pkgconfig_utils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parse_profile_from_opts() {
|
||||
let options = Options {
|
||||
args: vec![
|
||||
"build".into(),
|
||||
"--".into(),
|
||||
"--profile".into(),
|
||||
"testing".into(),
|
||||
"--features".into(),
|
||||
"feat1".into(),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(get_profile(&options), "testing");
|
||||
|
||||
let options = Options {
|
||||
args: vec![
|
||||
"build".into(),
|
||||
"--".into(),
|
||||
"--profile=customprofile".into(),
|
||||
"testing".into(),
|
||||
"--features".into(),
|
||||
"feat1".into(),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(get_profile(&options), "customprofile");
|
||||
|
||||
let options = Options {
|
||||
debug: true,
|
||||
args: vec![
|
||||
"build".into(),
|
||||
"--".into(),
|
||||
"testing".into(),
|
||||
"--features".into(),
|
||||
"feat1".into(),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(get_profile(&options), "dev");
|
||||
|
||||
let options = Options {
|
||||
debug: false,
|
||||
args: vec![
|
||||
"build".into(),
|
||||
"--".into(),
|
||||
"testing".into(),
|
||||
"--features".into(),
|
||||
"feat1".into(),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(get_profile(&options), "release");
|
||||
|
||||
let options = Options {
|
||||
args: vec!["build".into(), "--".into(), "--profile".into()],
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(get_profile(&options), "release");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user