summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyohei Uto <im@kyoheiu.dev>2024-01-14 05:15:22 +0900
committerKyohei Uto <im@kyoheiu.dev>2024-01-14 05:15:22 +0900
commit55d69b525be94e0712c8e761e7ee9bd980ff2e33 (patch)
treefca80a7382035f9096fdd1b2d195a845d21f74cc
parentc65961c29e2f59c2cbfa0671cf431e7bd226f18a (diff)
Create the target file if not exists and quit after selection
-rw-r--r--src/main.rs4
-rw-r--r--src/run.rs6
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;
}
}
}