@@ -28,6 +28,10 @@ struct Cli {
28
28
#[ arg( short, long, value_name = "version" ) ]
29
29
pub version : Option < String > ,
30
30
31
+ /// Whether we should clean the run directory.
32
+ #[ arg( short, long, value_name = "clean" ) ]
33
+ pub clean : bool ,
34
+
31
35
#[ command( subcommand) ]
32
36
pub command : Option < Commands > ,
33
37
}
@@ -83,10 +87,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
83
87
fetch_versions ( ) . await
84
88
} ;
85
89
86
- run ( versions) . await
90
+ let run_dir = if current_dir ( ) ?. ends_with ( "run" ) {
91
+ current_dir ( ) ?
92
+ } else {
93
+ current_dir ( ) ?. join ( "run" )
94
+ } ;
95
+
96
+ if cli. clean {
97
+ info ! ( "Cleaning run directory" ) ;
98
+ fs:: remove_dir_all ( & run_dir) ?;
99
+ fs:: create_dir_all ( & run_dir) ?;
100
+ }
101
+
102
+ run ( versions, run_dir) . await
87
103
}
88
104
89
- async fn run ( versions : Vec < String > ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
105
+ async fn run ( versions : Vec < String > , run_dir : PathBuf ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
90
106
let config_file = PathBuf :: from ( "config.toml" ) ;
91
107
if !fs:: exists ( & config_file) ? {
92
108
fs:: write ( config_file, toml:: to_string_pretty ( & Config :: default ( ) ) ?) ?;
@@ -106,12 +122,6 @@ async fn run(versions: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
106
122
107
123
let vanilla_jar_regex = Regex :: new ( VANILLA_JAR_REGEX ) ?;
108
124
109
- let run_dir = if current_dir ( ) ?. ends_with ( "run" ) {
110
- current_dir ( ) ?
111
- } else {
112
- current_dir ( ) ?. join ( "run" )
113
- } ;
114
-
115
125
if !run_dir. exists ( ) {
116
126
fs:: create_dir_all ( & run_dir) ?;
117
127
}
0 commit comments