#[macro_use]
extern crate clapme;
use clapme::ClapMe;
use std::io::{Write,BufRead};
#[test]
fn guide() {
let mut strings = Vec::new();
#[derive(ClapMe)]
struct Foo {
foo: bool,
}
strings.push(Foo::help_message("foo"));
#[derive(ClapMe)]
#[allow(non_snake_case)]
struct Flags {
verbose: bool,
blue_is_nice: bool,
min_T: bool,
}
strings.push(Flags::help_message("flags"));
#[derive(ClapMe)]
#[allow(non_snake_case)]
struct Help {
verbose: bool,
min_T: bool,
}
strings.push(Help::help_message("help"));
#[derive(ClapMe)]
#[allow(non_snake_case)]
struct Types {
name: String,
T: f64,
directory: std::path::PathBuf,
}
strings.push(Types::help_message("types"));
#[derive(ClapMe)]
struct Optional {
name: Option<String>,
}
strings.push(Optional::help_message("optional"));
#[derive(ClapMe)]
enum Exclusive {
First {
a: String,
b: String,
},
SecondFlag(String),
Third_,
}
strings.push(Exclusive::help_message("exclusive"));
#[derive(ClapMe)]
struct Vec2d {
x: f64, y: f64,
}
#[derive(ClapMe)]
struct Nested {
position: Vec2d,
velocity: Vec2d,
}
strings.push(Nested::help_message("nested"));
#[derive(ClapMe)]
struct MyConfig {
name: String,
}
#[derive(ClapMe)]
struct YourConfig {
address: String,
}
#[derive(ClapMe)]
struct Flattened {
_mine: MyConfig,
_yours: YourConfig,
}
strings.push(Flattened::help_message("flattened"));
strings.reverse();
println!("current dir is {:?}", std::env::current_dir());
println!("hello world");
let src = std::path::Path::new("tests/create-guide.rs");
println!("hello world");
let dest = std::path::Path::new("src/guide.rs");
println!("creating {:?}", &dest);
let mut f = std::fs::File::create(&dest).unwrap();
println!("opening {:?}", &src);
let i = std::fs::File::open(&src).unwrap();
let lines = std::io::BufReader::new(&i);
let mut am_writing = false;
let mut chars_to_trim = 0;
for line in lines.lines() {
let l: String = line.unwrap();
if l.contains(&format!("{}{}", "//","/")) && !am_writing {
let l = l.replacen(&format!("{}{}", "//","/"), "", 1);
writeln!(f, "//! {}", &l.trim()).unwrap();
} else if l.contains(&format!("{} {}", "START", "CODE")) {
am_writing = true;
chars_to_trim = l.find(|c: char| !c.is_whitespace()).unwrap();
writeln!(f, "//! ```").unwrap();
} else if l.contains(&format!("{} {}", "IGNORE", "CODE")) {
am_writing = true;
chars_to_trim = l.find(|c: char| !c.is_whitespace()).unwrap();
writeln!(f, "//! ```ignore").unwrap();
} else if l.contains(&format!("{} {}", "STOP", "CODE")) {
am_writing = false;
writeln!(f, "//! ```").unwrap();
} else if l.contains(&format!("{}.{}", "strings", "push")) {
let val = strings.pop().unwrap();
writeln!(f, "//! ```ignore").unwrap();
for ll in val.lines() {
writeln!(f, "//! {}", &ll).unwrap();
}
writeln!(f, "//! ```").unwrap();
} else if am_writing {
writeln!(f, "//! {}", &l.split_at(chars_to_trim).1).unwrap();
}
}
}