use crate::{readme, utils};
use clap::{Arg, ArgAction, ArgMatches, Command, arg, command, crate_version};
enum Action {
Readme(
String,
),
Nothing,
}
fn get_matches() -> ArgMatches {
command!()
.disable_version_flag(true)
.arg(Arg::new("version").short('V').long("version").help("Print version").action(ArgAction::SetTrue))
.subcommand(
Command::new("readme")
.about("Scaffolds README.md file")
.display_order(1)
.arg(arg!(<README_BODY>).help("File containing the body of the scaffolded README.md").required(true).index(1)),
)
.get_matches()
}
fn get_cli_action() -> Action {
let matches = get_matches();
if matches.get_flag("version") {
println!("{}", crate_version!());
return Action::Nothing;
}
match matches.subcommand() {
Some(("readme", matches)) => {
return Action::Readme(match_string(matches, "README_BODY"));
}
_ => {}
}
Action::Nothing
}
pub fn do_action() {
match get_cli_action() {
Action::Readme(file_name) => {
let contents = readme::scaffold_readme(file_name);
utils::write_file("README.md", &contents);
}
Action::Nothing => {
}
}
}
fn match_string(matches: &ArgMatches, name: &str) -> String {
matches.get_one::<String>(name).unwrap().to_string()
}