@@ -46,7 +46,7 @@ mod manifest;
46
46
use cargo_config:: Config as CargoConfig ;
47
47
use manifest:: { rewrite_manifest, Manifest } ;
48
48
49
- #[ derive( Debug , Clone ) ]
49
+ #[ derive( Debug , Clone , Default ) ]
50
50
pub struct Options {
51
51
pub runner : Option < String > ,
52
52
pub debug : bool ,
@@ -1022,9 +1022,14 @@ pub fn get_profile(options: &Options) -> &str {
1022
1022
options
1023
1023
. args
1024
1024
. 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" } )
1028
1033
}
1029
1034
1030
1035
pub fn get_profile_dir ( options : & Options ) -> & str {
@@ -1247,3 +1252,69 @@ fn tauri_config_to_bundle_settings(
1247
1252
..Default :: default ( )
1248
1253
} )
1249
1254
}
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