Skip to content

Commit a666514

Browse files
committed
feat: --clean
1 parent bd66778 commit a666514

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/main.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ struct Cli {
2828
#[arg(short, long, value_name = "version")]
2929
pub version: Option<String>,
3030

31+
/// Whether we should clean the run directory.
32+
#[arg(short, long, value_name = "clean")]
33+
pub clean: bool,
34+
3135
#[command(subcommand)]
3236
pub command: Option<Commands>,
3337
}
@@ -83,10 +87,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
8387
fetch_versions().await
8488
};
8589

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
87103
}
88104

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>> {
90106
let config_file = PathBuf::from("config.toml");
91107
if !fs::exists(&config_file)? {
92108
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>> {
106122

107123
let vanilla_jar_regex = Regex::new(VANILLA_JAR_REGEX)?;
108124

109-
let run_dir = if current_dir()?.ends_with("run") {
110-
current_dir()?
111-
} else {
112-
current_dir()?.join("run")
113-
};
114-
115125
if !run_dir.exists() {
116126
fs::create_dir_all(&run_dir)?;
117127
}

0 commit comments

Comments
 (0)