use clap::{App, Shell};
use structopt::StructOpt;
#[derive(StructOpt)]
#[structopt(
name = "minittc",
rename_all = "kebab-case",
raw(setting = "structopt::clap::AppSettings::ColoredHelp")
)]
pub struct CliOptions {
#[structopt(short = "p", long)]
pub parse_only: bool,
#[structopt(short = "g", long)]
pub generated: bool,
#[structopt(alias = "repl", short = "i", long)]
pub interactive: bool,
#[structopt(alias = "repl-plain", short = "j", long)]
pub interactive_plain: bool,
#[structopt(short = "q", long)]
pub quiet: bool,
#[structopt(name = "FILE")]
pub file: Option<String>,
#[structopt(subcommand)]
completion: Option<GenShellSubCommand>,
}
#[derive(StructOpt)]
#[structopt(rename_all = "kebab-case")]
enum GenShellSubCommand {
Completion {
#[structopt(
name = "generate-completion-script-for",
alias = "gcf",
raw(possible_values = "&Shell::variants()", case_insensitive = "true")
)]
shell: Shell,
},
}
fn app<'a, 'b>() -> App<'a, 'b> {
let extra_help = "For extra help please head to \
https://github.com/owo-lang/minitt-rs/issues/new";
let app: App = CliOptions::clap();
app.after_help(extra_help)
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.about(env!("CARGO_PKG_DESCRIPTION"))
}
pub fn pre() -> CliOptions {
let args: CliOptions = CliOptions::from_clap(&app().get_matches());
if let Some(GenShellSubCommand::Completion { shell }) = args.completion {
app().gen_completions_to("minittc", shell, &mut std::io::stdout());
}
args
}