From 55d69b525be94e0712c8e761e7ee9bd980ff2e33 Mon Sep 17 00:00:00 2001 From: Kyohei Uto Date: Sun, 14 Jan 2024 05:15:22 +0900 Subject: [PATCH] Create the target file if not exists and quit after selection --- src/main.rs | 4 +--- src/run.rs | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3a33a62..699da68 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,9 +49,7 @@ fn main() -> Result<(), errors::FxError> { _ => { if args[1].starts_with("--choosefiles=") { let target_path = PathBuf::from(args[1].split('=').nth(1).unwrap()); - if !target_path.exists() { - eprintln!("Target path does not exists."); - } else if let Err(e) = run::run( + if let Err(e) = run::run( std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")), false, Some(target_path), diff --git a/src/run.rs b/src/run.rs index 262120e..76b552f 100644 --- a/src/run.rs +++ b/src/run.rs @@ -491,6 +491,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> { if let Some(target_path) = &state.choosefiles_target { match std::fs::File::options() .append(true) + .create_new(true) .open(target_path) { Err(e) => print_warning(e, state.layout.y), @@ -502,10 +503,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> { ) { print_warning(e, state.layout.y); } else { - print_info( - "Path written to the file.", - state.layout.y, - ); + break 'main; } } }