Skip to content

Commit

Permalink
fix(cli): parse --profile=<profile> syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Jun 27, 2024
1 parent 63da834 commit 0ff05ad
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changes/cli-profile-parse-syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": "patch:bug"
"@tauri-apps/cli": "patch:bug"
---

Fix parsing of cargo profile when using `--profile=<profile>` syntax.
71 changes: 68 additions & 3 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,9 +1022,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"))
.map(|i| {
options.args[i]
.split_once("=")
.map(|(_, p)| p)
.unwrap_or_else(|| &options.args[i + 1])
})
.unwrap_or_else(|| if options.debug { "dev" } else { "release" })
}

pub fn get_profile_dir(options: &Options) -> &str {
Expand Down Expand Up @@ -1247,3 +1252,63 @@ fn tauri_config_to_bundle_settings(
..Default::default()
})
}

#[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");
}
}

0 comments on commit 0ff05ad

Please sign in to comment.