Skip to content

Commit 08f57ef

Browse files
fix(cli): parse --profile=<profile> syntax (#10136)
* fix(cli): parse `--profile=<profile>` syntax ref: #6255 (comment) * Update tooling/cli/src/interface/rust.rs * derive default * safe check next arg --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 63da834 commit 08f57ef

File tree

2 files changed

+81
-4
lines changed

2 files changed

+81
-4
lines changed

.changes/cli-profile-parse-syntax.md

+6
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

+75-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ mod manifest;
4646
use cargo_config::Config as CargoConfig;
4747
use manifest::{rewrite_manifest, Manifest};
4848

49-
#[derive(Debug, Clone)]
49+
#[derive(Debug, Clone, Default)]
5050
pub struct Options {
5151
pub runner: Option<String>,
5252
pub debug: bool,
@@ -1022,9 +1022,14 @@ pub fn get_profile(options: &Options) -> &str {
10221022
options
10231023
.args
10241024
.iter()
1025-
.position(|a| a == "--profile")
1026-
.map(|i| options.args[i + 1].as_str())
1027-
.unwrap_or_else(|| if options.debug { "debug" } else { "release" })
1025+
.position(|a| a.starts_with("--profile"))
1026+
.and_then(|i| {
1027+
options.args[i]
1028+
.split_once('=')
1029+
.map(|(_, p)| Some(p))
1030+
.unwrap_or_else(|| options.args.get(i + 1).map(|s| s.as_str()))
1031+
})
1032+
.unwrap_or(if options.debug { "dev" } else { "release" })
10281033
}
10291034

10301035
pub fn get_profile_dir(options: &Options) -> &str {
@@ -1247,3 +1252,69 @@ fn tauri_config_to_bundle_settings(
12471252
..Default::default()
12481253
})
12491254
}
1255+
1256+
#[cfg(test)]
1257+
mod tests {
1258+
use super::*;
1259+
1260+
#[test]
1261+
fn parse_profile_from_opts() {
1262+
let options = Options {
1263+
args: vec![
1264+
"build".into(),
1265+
"--".into(),
1266+
"--profile".into(),
1267+
"testing".into(),
1268+
"--features".into(),
1269+
"feat1".into(),
1270+
],
1271+
..Default::default()
1272+
};
1273+
assert_eq!(get_profile(&options), "testing");
1274+
1275+
let options = Options {
1276+
args: vec![
1277+
"build".into(),
1278+
"--".into(),
1279+
"--profile=customprofile".into(),
1280+
"testing".into(),
1281+
"--features".into(),
1282+
"feat1".into(),
1283+
],
1284+
..Default::default()
1285+
};
1286+
assert_eq!(get_profile(&options), "customprofile");
1287+
1288+
let options = Options {
1289+
debug: true,
1290+
args: vec![
1291+
"build".into(),
1292+
"--".into(),
1293+
"testing".into(),
1294+
"--features".into(),
1295+
"feat1".into(),
1296+
],
1297+
..Default::default()
1298+
};
1299+
assert_eq!(get_profile(&options), "dev");
1300+
1301+
let options = Options {
1302+
debug: false,
1303+
args: vec![
1304+
"build".into(),
1305+
"--".into(),
1306+
"testing".into(),
1307+
"--features".into(),
1308+
"feat1".into(),
1309+
],
1310+
..Default::default()
1311+
};
1312+
assert_eq!(get_profile(&options), "release");
1313+
1314+
let options = Options {
1315+
args: vec!["build".into(), "--".into(), "--profile".into()],
1316+
..Default::default()
1317+
};
1318+
assert_eq!(get_profile(&options), "release");
1319+
}
1320+
}

0 commit comments

Comments
 (0)