diff options
author | Jovansonlee Cesar <ivanceras@gmail.com> | 2018-03-04 04:00:37 +0800 |
---|---|---|
committer | Jovansonlee Cesar <ivanceras@gmail.com> | 2018-03-04 04:00:37 +0800 |
commit | 203ea60ebe607485ad98a1d39abe208f25dcd29e (patch) | |
tree | 908c6361c571f0aead0a371af584ba88f244c9de /svgbob_cli | |
parent | c6348be56cbc7acbe667105bfe989e58a74f7dbd (diff) |
cargo fmt
Diffstat (limited to 'svgbob_cli')
-rw-r--r-- | svgbob_cli/examples/ascii_art.rs | 13 | ||||
-rw-r--r-- | svgbob_cli/examples/comic.rs | 9 | ||||
-rw-r--r-- | svgbob_cli/examples/demo.rs | 14 | ||||
-rw-r--r-- | svgbob_cli/examples/memes2.rs | 9 | ||||
-rw-r--r-- | svgbob_cli/examples/memes3.rs | 9 | ||||
-rw-r--r-- | svgbob_cli/examples/render.rs | 9 | ||||
-rw-r--r-- | svgbob_cli/examples/simple.rs | 4 | ||||
-rw-r--r-- | svgbob_cli/src/main.rs | 87 |
8 files changed, 83 insertions, 71 deletions
diff --git a/svgbob_cli/examples/ascii_art.rs b/svgbob_cli/examples/ascii_art.rs index e2d9e8f..eaa18f7 100644 --- a/svgbob_cli/examples/ascii_art.rs +++ b/svgbob_cli/examples/ascii_art.rs @@ -4,8 +4,8 @@ use std::fs::File; use std::collections::BTreeMap; use handlebars::Handlebars; -extern crate svgbob; extern crate svg; +extern crate svgbob; use handlebars::Context; @@ -14,24 +14,23 @@ fn main() { let html_file = "ascii_art.html"; let bob_str = include_str!("ascii_art.bob"); let svg = svgbob::to_svg(bob_str); - if let Ok(_) = svg::save(svg_file, &svg){ - println!("Saved to {}",svg_file); - }else{ + if let Ok(_) = svg::save(svg_file, &svg) { + println!("Saved to {}", svg_file); + } else { println!("Error saving to file {}", svg_file); } let handlebars = Handlebars::new(); let mut m: BTreeMap<String, String> = BTreeMap::new(); - m.insert("bob".to_string(),bob_str.to_owned()); + m.insert("bob".to_string(), bob_str.to_owned()); m.insert("svg_file".to_string(), svg_file.to_string()); let context = Context::wraps(&m); - let mut source_template = File::open(&"web/index.hbs").unwrap(); let mut output_file = File::create(html_file).unwrap(); if let Ok(_) = handlebars.template_renderw2(&mut source_template, &context, &mut output_file) { println!("Rendered to {}", html_file); } else { - println!("Error"); + println!("Error"); }; } diff --git a/svgbob_cli/examples/comic.rs b/svgbob_cli/examples/comic.rs index 50d633e..3987a81 100644 --- a/svgbob_cli/examples/comic.rs +++ b/svgbob_cli/examples/comic.rs @@ -4,8 +4,8 @@ use std::fs::File; use std::collections::BTreeMap; use handlebars::Handlebars; -extern crate svgbob; extern crate svg; +extern crate svgbob; use handlebars::Context; @@ -15,20 +15,19 @@ fn main() { let bob_str = include_str!("comic.bob"); let svg = svgbob::to_svg(bob_str); svg::save(svg_file, &svg).unwrap(); - println!("Saved to {}",svg_file); + println!("Saved to {}", svg_file); let handlebars = Handlebars::new(); let mut m: BTreeMap<String, String> = BTreeMap::new(); - m.insert("bob".to_string(),bob_str.to_owned()); + m.insert("bob".to_string(), bob_str.to_owned()); m.insert("svg_file".to_string(), svg_file.to_string()); let context = Context::wraps(&m); - let mut source_template = File::open(&"web/index.hbs").unwrap(); let mut output_file = File::create(html_file).unwrap(); if let Ok(_) = handlebars.template_renderw2(&mut source_template, &context, &mut output_file) { println!("Rendered to {}", html_file); } else { - println!("Error"); + println!("Error"); }; } diff --git a/svgbob_cli/examples/demo.rs b/svgbob_cli/examples/demo.rs index 0e893d2..f81bdd2 100644 --- a/svgbob_cli/examples/demo.rs +++ b/svgbob_cli/examples/demo.rs @@ -1,21 +1,19 @@ -extern crate svgbob; extern crate svg; +extern crate svgbob; use svgbob::Grid; use svgbob::Settings; - fn main() { let file = "examples/demo.svg"; - let g = Grid::from_str(get_arg(),&Settings::compact()); + let g = Grid::from_str(get_arg(), &Settings::compact()); let svg = g.get_svg(); svg::save(file, &svg).unwrap(); - println!("Saved to {}",file); + println!("Saved to {}", file); } -fn get_arg() -> &'static str{ - -let arg = r#" +fn get_arg() -> &'static str { + let arg = r#" +------+ +-----+ +-----+ +-----+ @@ -127,5 +125,5 @@ let arg = r#" "#; -arg + arg } diff --git a/svgbob_cli/examples/memes2.rs b/svgbob_cli/examples/memes2.rs index d850fe4..b03fc85 100644 --- a/svgbob_cli/examples/memes2.rs +++ b/svgbob_cli/examples/memes2.rs @@ -4,8 +4,8 @@ use std::fs::File; use std::collections::BTreeMap; use handlebars::Handlebars; -extern crate svgbob; extern crate svg; +extern crate svgbob; use handlebars::Context; @@ -15,20 +15,19 @@ fn main() { let bob_str = include_str!("memes2.bob"); let svg = svgbob::to_svg(bob_str); svg::save(svg_file, &svg).unwrap(); - println!("Saved to {}",svg_file); + println!("Saved to {}", svg_file); let handlebars = Handlebars::new(); let mut m: BTreeMap<String, String> = BTreeMap::new(); - m.insert("bob".to_string(),bob_str.to_owned()); + m.insert("bob".to_string(), bob_str.to_owned()); m.insert("svg_file".to_string(), svg_file.to_string()); let context = Context::wraps(&m); - let mut source_template = File::open(&"web/index.hbs").unwrap(); let mut output_file = File::create(html_file).unwrap(); if let Ok(_) = handlebars.template_renderw2(&mut source_template, &context, &mut output_file) { println!("Rendered to {}", html_file); } else { - println!("Error"); + println!("Error"); }; } diff --git a/svgbob_cli/examples/memes3.rs b/svgbob_cli/examples/memes3.rs index 6d43879..140b9f4 100644 --- a/svgbob_cli/examples/memes3.rs +++ b/svgbob_cli/examples/memes3.rs @@ -4,8 +4,8 @@ use std::fs::File; use std::collections::BTreeMap; use handlebars::Handlebars; -extern crate svgbob; extern crate svg; +extern crate svgbob; use handlebars::Context; @@ -15,20 +15,19 @@ fn main() { let bob_str = include_str!("memes3.bob"); let svg = svgbob::to_svg(bob_str); svg::save(svg_file, &svg).unwrap(); - println!("Saved to {}",svg_file); + println!("Saved to {}", svg_file); let handlebars = Handlebars::new(); let mut m: BTreeMap<String, String> = BTreeMap::new(); - m.insert("bob".to_string(),bob_str.to_owned()); + m.insert("bob".to_string(), bob_str.to_owned()); m.insert("svg_file".to_string(), svg_file.to_string()); let context = Context::wraps(&m); - let mut source_template = File::open(&"web/index.hbs").unwrap(); let mut output_file = File::create(html_file).unwrap(); if let Ok(_) = handlebars.template_renderw2(&mut source_template, &context, &mut output_file) { println!("Rendered to {}", html_file); } else { - println!("Error"); + println!("Error"); }; } diff --git a/svgbob_cli/examples/render.rs b/svgbob_cli/examples/render.rs index 9253749..1047f6c 100644 --- a/svgbob_cli/examples/render.rs +++ b/svgbob_cli/examples/render.rs @@ -4,8 +4,8 @@ use std::fs::File; use std::collections::BTreeMap; use handlebars::Handlebars; -extern crate svgbob; extern crate svg; +extern crate svgbob; use handlebars::Context; @@ -15,20 +15,19 @@ fn main() { let bob_str = include_str!("long.bob"); let svg = svgbob::to_svg(bob_str); svg::save(svg_file, &svg).unwrap(); - println!("Saved to {}",svg_file); + println!("Saved to {}", svg_file); let handlebars = Handlebars::new(); let mut m: BTreeMap<String, String> = BTreeMap::new(); - m.insert("bob".to_string(),bob_str.to_owned()); + m.insert("bob".to_string(), bob_str.to_owned()); m.insert("svg_file".to_string(), svg_file.to_string()); let context = Context::wraps(&m); - let mut source_template = File::open(&"web/index.hbs").unwrap(); let mut output_file = File::create(html_file).unwrap(); if let Ok(_) = handlebars.template_renderw2(&mut source_template, &context, &mut output_file) { println!("Rendered to {}", html_file); } else { - println!("Error"); + println!("Error"); }; } diff --git a/svgbob_cli/examples/simple.rs b/svgbob_cli/examples/simple.rs index 4d1d1fa..5c74d50 100644 --- a/svgbob_cli/examples/simple.rs +++ b/svgbob_cli/examples/simple.rs @@ -1,10 +1,10 @@ extern crate svgbob; -fn main(){ +fn main() { let input = r#" .-------------------------------------. | Hello here and there and everywhere | '-------------------------------------' "#; - println!("svg: {}",svgbob::to_svg(input)); + println!("svg: {}", svgbob::to_svg(input)); } diff --git a/svgbob_cli/src/main.rs b/svgbob_cli/src/main.rs index 87ee957..0b86583 100644 --- a/svgbob_cli/src/main.rs +++ b/svgbob_cli/src/main.rs @@ -2,8 +2,8 @@ #[macro_use] extern crate clap; -extern crate svgbob; extern crate svg; +extern crate svgbob; use svgbob::Grid; use svgbob::Settings; @@ -17,7 +17,7 @@ use std::process::exit; use std::str::FromStr; fn main() { - use clap::{Arg, App, SubCommand}; + use clap::{App, Arg, SubCommand}; let args = App::new("svgbob") .version(crate_version!()) @@ -71,7 +71,10 @@ fn main() { let mut bob = String::new(); if args.is_present("inline") { - bob = args.value_of("input").unwrap().replace("\\n","\n").to_string(); + bob = args.value_of("input") + .unwrap() + .replace("\\n", "\n") + .to_string(); } else { if let Some(file) = args.value_of("input") { match File::open(file) { @@ -82,11 +85,12 @@ fn main() { use std::io::Write; use std::process::exit; - writeln!(&mut std::io::stderr(), - "Failed to open input file {}: {}", - file, - e) - .unwrap(); + writeln!( + &mut std::io::stderr(), + "Failed to open input file {}: {}", + file, + e + ).unwrap(); exit(1); } } @@ -122,11 +126,12 @@ fn main() { use std::io::Write; use std::process::exit; - writeln!(&mut std::io::stderr(), - "Failed to write to output file {}: {}", - file, - e) - .unwrap(); + writeln!( + &mut std::io::stderr(), + "Failed to write to output file {}: {}", + file, + e + ).unwrap(); exit(2); } } else { @@ -134,31 +139,39 @@ fn main() { } } -fn parse_value_of<T: FromStr>(args: &ArgMatches, arg_name: &str) -> Option<T> where <T as std::str::FromStr>::Err: std::fmt::Display { - return args.value_of(arg_name).and_then(|arg| match arg.parse::<T>() { - Ok(a) => Some(a), - Err(e) => { - use std::io::Write; - use std::process::exit; - - writeln!(&mut std::io::stderr(), - "Illegal value for argument {}: {}", - arg_name, - e) - .unwrap(); - exit(1); - } - }); +fn parse_value_of<T: FromStr>(args: &ArgMatches, arg_name: &str) -> Option<T> +where + <T as std::str::FromStr>::Err: std::fmt::Display, +{ + return args.value_of(arg_name) + .and_then(|arg| match arg.parse::<T>() { + Ok(a) => Some(a), + Err(e) => { + use std::io::Write; + use std::process::exit; + + writeln!( + &mut std::io::stderr(), + "Illegal value for argument {}: {}", + arg_name, + e + ).unwrap(); + exit(1); + } + }); } // Batch convert files to svg // use svgbob build -i inputdir/*.bob -o outdir/ fn build(args: &ArgMatches) -> Result<(), Box<Error>> { - let files_pattern = args.value_of("input").unwrap_or("*.bob"); let outdir = args.value_of("outdir").unwrap_or(""); let input_path = Path::new(files_pattern); - let ext = input_path.extension().unwrap_or(&"bob".as_ref()).to_str().unwrap(); + let ext = input_path + .extension() + .unwrap_or(&"bob".as_ref()) + .to_str() + .unwrap(); let input_dir = if input_path.is_dir() { input_path.clone() @@ -167,8 +180,10 @@ fn build(args: &ArgMatches) -> Result<(), Box<Error>> { }; if !input_dir.is_dir() { - return Err(Box::from(format!("[Error]: No such dir name is {} !", - input_dir.to_string_lossy()))); + return Err(Box::from(format!( + "[Error]: No such dir name is {} !", + input_dir.to_string_lossy() + ))); } let mut out_path = PathBuf::new(); @@ -186,7 +201,11 @@ fn build(args: &ArgMatches) -> Result<(), Box<Error>> { for path in paths { let tmp_path = path.unwrap().path(); if tmp_path.is_file() { - let tmp_ext = tmp_path.extension().unwrap_or(&"".as_ref()).to_str().unwrap(); + let tmp_ext = tmp_path + .extension() + .unwrap_or(&"".as_ref()) + .to_str() + .unwrap(); if tmp_ext == ext { let name = tmp_path.file_stem().unwrap().to_str().unwrap(); let mut tmp = out_path.clone(); @@ -209,7 +228,7 @@ fn convert_file(input: PathBuf, output: PathBuf) -> Result<(), Box<Error>> { let mut bob = String::new(); let mut f = try!(File::open(&input)); f.read_to_string(&mut bob).unwrap(); - let g = Grid::from_str(&*bob,&Settings::compact()); + let g = Grid::from_str(&*bob, &Settings::compact()); let svg = g.get_svg(); try!(svg::save(&output, &svg)); Ok(()) |