diff options
author | yhql <yhql@users.noreply.github.com> | 2017-09-03 14:55:31 +0200 |
---|---|---|
committer | yhql <yhql@users.noreply.github.com> | 2017-09-03 14:55:31 +0200 |
commit | bd136713d3bdb0d3d0aacb7c6467a65c8f924c1d (patch) | |
tree | 3626fc15df05d4d8415f4f68cc3a01d4018d92fe /svgbob_cli | |
parent | e785e26ca56ad9eef13a61e98c0201df216159b3 (diff) |
issue 15
New flag to handle inline string parsing
Diffstat (limited to 'svgbob_cli')
-rw-r--r-- | svgbob_cli/src/main.rs | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/svgbob_cli/src/main.rs b/svgbob_cli/src/main.rs index 18ed74c..efcd155 100644 --- a/svgbob_cli/src/main.rs +++ b/svgbob_cli/src/main.rs @@ -21,7 +21,8 @@ fn main() { let args = App::new("svgbob") .version(crate_version!()) .about("SvgBobRus is an ascii to svg converter") - .arg(Arg::with_name("input").index(1).help("svgbob text file to parse [default: STDIN]")) + .arg(Arg::with_name("inline").short("s").help("parse an inline string")) + .arg(Arg::with_name("input").index(1).help("svgbob text file or inline string to parse [default: STDIN]")) .arg(Arg::with_name("output") .short("o") .long("output") @@ -51,26 +52,31 @@ fn main() { } let mut bob = String::new(); - if let Some(file) = args.value_of("input") { - match File::open(file) { - Ok(mut f) => { - f.read_to_string(&mut bob).unwrap(); - } - Err(e) => { - use std::io::Write; - use std::process::exit; - - writeln!(&mut std::io::stderr(), - "Failed to open input file {}: {}", - file, - e) - .unwrap(); - exit(1); + + if args.is_present("inline") { + bob = args.value_of("input").unwrap().replace("\\n","\n").to_string(); + } else { + if let Some(file) = args.value_of("input") { + match File::open(file) { + Ok(mut f) => { + f.read_to_string(&mut bob).unwrap(); + } + Err(e) => { + use std::io::Write; + use std::process::exit; + + writeln!(&mut std::io::stderr(), + "Failed to open input file {}: {}", + file, + e) + .unwrap(); + exit(1); + } } + } else { + use std::io; + io::stdin().read_to_string(&mut bob).unwrap(); } - } else { - use std::io; - io::stdin().read_to_string(&mut bob).unwrap(); } let g = Grid::from_str(&*bob, &Settings::compact()); |