diff --git a/README.md b/README.md index 7e1d414..2e37580 100644 --- a/README.md +++ b/README.md @@ -378,6 +378,7 @@ OPTIONS: -x, --regexp ... Use this regexp as extra pattern to match --select-bg-color Sets the background color for selection [default: black] --select-fg-color Sets the foreground color for selection [default: blue] + -t, --target Stores the hint in the specified path ``` diff --git a/src/main.rs b/src/main.rs index b8e3395..eda20eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -109,8 +109,8 @@ fn app_args<'a>() -> clap::ArgMatches<'a> { Arg::with_name("target") .help("Stores the hint in the specified path") .long("target") - .default_value("") - .short("t"), + .short("t") + .takes_value(true), ) .get_matches() } @@ -120,7 +120,7 @@ fn main() { let format = args.value_of("format").unwrap(); let alphabet = args.value_of("alphabet").unwrap(); let position = args.value_of("position").unwrap(); - let target = args.value_of("target").unwrap(); + let target = args.value_of("target"); let multi = args.is_present("multi"); let reverse = args.is_present("reverse"); let unique = args.is_present("unique"); @@ -182,9 +182,7 @@ fn main() { .collect::>() .join("\n"); - if target.is_empty() { - print!("{}", output); - } else { + if let Some(target) = target { let mut file = OpenOptions::new() .create(true) .truncate(true) @@ -193,6 +191,8 @@ fn main() { .expect("Unable to open the target file"); file.write(output.as_bytes()).unwrap(); + } else { + print!("{}", output); } } else { ::std::process::exit(1);