summaryrefslogtreecommitdiffstats
path: root/svgbob_cli
diff options
context:
space:
mode:
authorivanceras <ivanceras@gmail.com>2017-09-04 14:43:17 +0800
committerGitHub <noreply@github.com>2017-09-04 14:43:17 +0800
commitc4d42cd18061c117ec3868ad54d7aa65747dc4e6 (patch)
tree5f6932d034c875044adc702e604b215c3730e3ef /svgbob_cli
parentab1c44b49657e856ab7e03e6c80c6972206504da (diff)
parentbd136713d3bdb0d3d0aacb7c6467a65c8f924c1d (diff)
Merge pull request #17 from yhql/master
New flag to handle inline string parsing
Diffstat (limited to 'svgbob_cli')
-rw-r--r--svgbob_cli/src/main.rs44
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());