#[macro_use]
extern crate auto_args;
use auto_args::AutoArgs;
use std::io::{BufRead, Write};
#[test]
fn guide() {
let mut strings = Vec::new();
#[derive(AutoArgs)]
struct Foo {
foo: bool,
}
strings.push(Foo::usage());
strings.push(Foo::help());
#[derive(AutoArgs)]
#[allow(non_snake_case)]
struct Help {
verbose: bool,
T: bool,
}
strings.push(Help::usage());
strings.push(Help::help());
#[derive(AutoArgs)]
#[allow(non_snake_case)]
struct Flags {
verbose: bool,
blue_is_nice_: bool,
min_T: bool,
}
strings.push(Flags::help());
#[derive(AutoArgs)]
#[allow(non_snake_case)]
struct Types {
name: String,
T: f64,
directory: std::path::PathBuf,
}
strings.push(Types::help());
#[derive(AutoArgs)]
struct Optional {
name: Option<String>,
}
strings.push(Optional::help());
#[derive(AutoArgs)]
enum Exclusive {
First {
a: String,
b: String,
},
SecondFlag(String),
Third_,
}
strings.push(Exclusive::usage());
strings.push(Exclusive::help());
#[derive(AutoArgs)]
struct Vec2d {
x: f64,
y: f64,
}
#[derive(AutoArgs)]
struct Nested {
position: Vec2d,
velocity: Vec2d,
}
strings.push(Nested::help());
#[derive(AutoArgs)]
struct MyConfig {
name: String,
}
#[derive(AutoArgs)]
struct YourConfig {
address: String,
}
#[derive(AutoArgs)]
struct Flattened {
_mine: MyConfig,
_yours: YourConfig,
}
strings.push(Flattened::usage());
strings.push(Flattened::help());
strings.reverse();
let src = std::path::Path::new("tests/create-guide.rs");
let dest = std::path::Path::new("src/guide.rs");
let mut f = std::fs::File::create(&dest).unwrap();
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();
}
}
}