@@ -2,7 +2,6 @@ use std::env::{split_paths, var_os};
2
2
use std:: fmt:: Debug ;
3
3
use std:: fs;
4
4
use std:: path:: PathBuf ;
5
- use std:: time:: { SystemTime , UNIX_EPOCH } ;
6
5
7
6
use clap:: Subcommand ;
8
7
use clap:: { builder:: BoolishValueParser , builder:: OsStr , Parser } ;
@@ -67,6 +66,10 @@ pub(crate) struct Normal {
67
66
#[ clap( env, short, long, value_parser = parse_absolute_path, required = true ) ]
68
67
pub ( crate ) game_directory : PathBuf ,
69
68
69
+ /// Instead of operating on an existing directory, create a new one with this flag as its name and then copy the original contents into it.
70
+ #[ clap( env, long, short = 'n' , required = false ) ]
71
+ pub ( crate ) new_game_directory : Option < PathBuf > ,
72
+
70
73
/// CommonOptions
71
74
#[ clap( flatten) ]
72
75
pub ( crate ) options : Options ,
@@ -92,26 +95,23 @@ pub(crate) struct Eet {
92
95
#[ clap( env, short='z' , long, value_parser = path_must_exist, required = true ) ]
93
96
pub ( crate ) bg2_log_file : PathBuf ,
94
97
95
- /// Instead of using given directories create new ones with files copied into them
98
+ /// Instead of operating on an existing directory, create a new one with this flag as its name and then copy the original contents into it.
96
99
#[ clap(
97
100
env,
98
- short= 'g' ,
101
+ short,
99
102
long,
100
103
action = clap:: ArgAction :: SetTrue ,
101
104
required = false ,
102
105
) ]
103
- pub ( crate ) create_directories : bool ,
106
+ pub ( crate ) generate_directories : bool ,
104
107
105
- /// When create_directories is true, this is the prefix which the created directories have
106
- #[ clap(
107
- env,
108
- long,
109
- short = 'p' ,
110
- default_value_t = SystemTime :: now( ) . duration_since( UNIX_EPOCH ) . unwrap( ) . as_secs( ) . to_string( ) ,
111
- default_missing_value = SystemTime :: now( ) . duration_since( UNIX_EPOCH ) . unwrap( ) . as_secs( ) . to_string( ) ,
112
- required = false
113
- ) ]
114
- pub ( crate ) create_directories_prefix : String ,
108
+ /// If generate_directories is true. This is the path for the new pre-eet directory.
109
+ #[ clap( env, short = 'p' , long, value_parser = path_must_exist) ]
110
+ pub ( crate ) new_pre_eet_dir : Option < PathBuf > ,
111
+
112
+ /// If generate_directories is true. This is the path for the new eet directory.
113
+ #[ clap( env, short = 'n' , long, value_parser = path_must_exist) ]
114
+ pub ( crate ) new_eet_dir : Option < PathBuf > ,
115
115
116
116
/// CommonOptions
117
117
#[ clap( flatten) ]
@@ -185,15 +185,26 @@ pub(crate) struct Options {
185
185
pub ( crate ) timeout : usize ,
186
186
187
187
/// Weidu log setting "--autolog" is default
188
- #[ clap( env, long, short='u' , default_value = "autolog" , value_parser = parse_weidu_log_mode, required = false ) ]
188
+ #[ clap(
189
+ env,
190
+ long,
191
+ short='u' ,
192
+ default_value = "autolog" ,
193
+ value_parser = parse_weidu_log_mode,
194
+ required = false
195
+ ) ]
189
196
pub ( crate ) weidu_log_mode : String ,
190
197
191
198
/// Strict Version and Component/SubComponent matching
192
199
#[ clap(
193
200
env,
194
201
short = 'x' ,
195
202
long,
203
+ num_args=0 ..=1 ,
196
204
action = clap:: ArgAction :: SetTrue ,
205
+ default_value_t = false ,
206
+ default_missing_value = "false" ,
207
+ value_parser = BoolishValueParser :: new( ) ,
197
208
required = false ,
198
209
) ]
199
210
pub ( crate ) strict_matching : bool ,
@@ -324,6 +335,7 @@ mod tests {
324
335
command : InstallType :: Normal ( Normal {
325
336
log_file : fake_log_file. clone ( ) ,
326
337
game_directory : fake_game_dir. clone ( ) ,
338
+ new_game_directory : None ,
327
339
options : Options {
328
340
weidu_binary : fake_weidu_bin. clone ( ) ,
329
341
mod_directories : vec ! [ fake_mod_dirs. clone( ) ] ,
@@ -333,7 +345,7 @@ mod tests {
333
345
abort_on_warnings : expected_flag_value,
334
346
timeout : 3600 ,
335
347
weidu_log_mode : "--autolog" . to_string ( ) ,
336
- strict_matching : true ,
348
+ strict_matching : false ,
337
349
} ,
338
350
} ) ,
339
351
} ;
@@ -360,7 +372,7 @@ mod tests {
360
372
let fake_game_dir = std:: env:: current_dir ( ) . unwrap ( ) . join ( "fixtures" ) ;
361
373
let fake_weidu_bin = fake_game_dir. clone ( ) . join ( "weidu" ) ;
362
374
let fake_log_file = fake_game_dir. clone ( ) . join ( "weidu.log" ) ;
363
- let prefix = "prefix" ;
375
+ let new_dir = PathBuf :: new ( ) . join ( "test" ) ;
364
376
let expected_flag_value = true ;
365
377
366
378
let expected = Args {
@@ -380,18 +392,19 @@ mod tests {
380
392
weidu_log_mode : "--autolog" . to_string ( ) ,
381
393
strict_matching : !expected_flag_value,
382
394
} ,
383
- create_directories : true ,
384
- create_directories_prefix : prefix. to_string ( ) ,
395
+ generate_directories : false ,
396
+ new_pre_eet_dir : None ,
397
+ new_eet_dir : Some ( "test" . into ( ) ) ,
385
398
} ) ,
386
399
} ;
387
400
let test_arg_string = format ! (
388
- "mod_installer eet -w {} -1 {} -y {} -2 {} -z {} -g -p {}" ,
401
+ "mod_installer eet -w {} -1 {} -y {} -2 {} -z {} -n {}" ,
389
402
fake_weidu_bin. to_str( ) . unwrap_or_default( ) ,
390
403
fake_game_dir. to_str( ) . unwrap_or_default( ) ,
391
404
fake_log_file. to_str( ) . unwrap_or_default( ) ,
392
405
fake_game_dir. to_str( ) . unwrap_or_default( ) ,
393
406
fake_log_file. to_str( ) . unwrap_or_default( ) ,
394
- prefix ,
407
+ new_dir . to_str ( ) . unwrap_or_default ( ) ,
395
408
) ;
396
409
let result = Args :: parse_from ( test_arg_string. split ( ' ' ) ) ;
397
410
assert_eq ! (
0 commit comments