Skip to content

Commit

Permalink
Create the target file if not exists and quit after selection
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoheiu committed Jan 13, 2024
1 parent c65961c commit 55d69b5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 2 additions & 4 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;
}
}
}
Expand Down

0 comments on commit 55d69b5

Please sign in to comment.