Skip to content

Commit 2783836

Browse files
fix(cli): parse --profile=<profile> syntax (#10135)
* fix(cli): parse `--profile=<profile>` syntax ref: #6255 (comment) * Update tooling/cli/src/interface/rust.rs * safe check next arg * add test --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 167b51a commit 2783836

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": "patch:bug"
3+
"@tauri-apps/cli": "patch:bug"
4+
---
5+
6+
Fix parsing of cargo profile when using `--profile=<profile>` syntax.

tooling/cli/src/interface/rust.rs

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,9 +1130,14 @@ pub fn get_profile(options: &Options) -> &str {
11301130
options
11311131
.args
11321132
.iter()
1133-
.position(|a| a == "--profile")
1134-
.map(|i| options.args[i + 1].as_str())
1135-
.unwrap_or_else(|| if options.debug { "debug" } else { "release" })
1133+
.position(|a| a.starts_with("--profile"))
1134+
.and_then(|i| {
1135+
options.args[i]
1136+
.split_once('=')
1137+
.map(|(_, p)| Some(p))
1138+
.unwrap_or_else(|| options.args.get(i + 1).map(|s| s.as_str()))
1139+
})
1140+
.unwrap_or(if options.debug { "dev" } else { "release" })
11361141
}
11371142

11381143
pub fn get_profile_dir(options: &Options) -> &str {
@@ -1457,3 +1462,69 @@ mod pkgconfig_utils {
14571462
}
14581463
}
14591464
}
1465+
1466+
#[cfg(test)]
1467+
mod tests {
1468+
use super::*;
1469+
1470+
#[test]
1471+
fn parse_profile_from_opts() {
1472+
let options = Options {
1473+
args: vec![
1474+
"build".into(),
1475+
"--".into(),
1476+
"--profile".into(),
1477+
"testing".into(),
1478+
"--features".into(),
1479+
"feat1".into(),
1480+
],
1481+
..Default::default()
1482+
};
1483+
assert_eq!(get_profile(&options), "testing");
1484+
1485+
let options = Options {
1486+
args: vec![
1487+
"build".into(),
1488+
"--".into(),
1489+
"--profile=customprofile".into(),
1490+
"testing".into(),
1491+
"--features".into(),
1492+
"feat1".into(),
1493+
],
1494+
..Default::default()
1495+
};
1496+
assert_eq!(get_profile(&options), "customprofile");
1497+
1498+
let options = Options {
1499+
debug: true,
1500+
args: vec![
1501+
"build".into(),
1502+
"--".into(),
1503+
"testing".into(),
1504+
"--features".into(),
1505+
"feat1".into(),
1506+
],
1507+
..Default::default()
1508+
};
1509+
assert_eq!(get_profile(&options), "dev");
1510+
1511+
let options = Options {
1512+
debug: false,
1513+
args: vec![
1514+
"build".into(),
1515+
"--".into(),
1516+
"testing".into(),
1517+
"--features".into(),
1518+
"feat1".into(),
1519+
],
1520+
..Default::default()
1521+
};
1522+
assert_eq!(get_profile(&options), "release");
1523+
1524+
let options = Options {
1525+
args: vec!["build".into(), "--".into(), "--profile".into()],
1526+
..Default::default()
1527+
};
1528+
assert_eq!(get_profile(&options), "release");
1529+
}
1530+
}

0 commit comments

Comments
 (0)