use std::{ffi::OsString, path::PathBuf};
use structopt::{clap::arg_enum, StructOpt};
#[derive(Clone, Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")]
#[structopt(setting(structopt::clap::AppSettings::ArgsNegateSubcommands))]
#[structopt(setting(structopt::clap::AppSettings::SubcommandsNegateReqs))]
pub struct Options {
#[structopt(long)]
pub pattern: Vec<String>,
#[structopt(long)]
pub config: Option<String>,
#[structopt(long, default_value = get_num_cpus())]
pub num_threads: usize,
#[structopt(
long,
possible_values = &DisplayStyle::variants(),
case_insensitive = true,
conflicts_with = "quiet",
)]
pub display_style: Option<DisplayStyle>,
#[structopt(long, short)]
pub quiet: bool,
#[structopt(
long,
possible_values = &Color::variants(),
case_insensitive = true,
default_value = "auto",
)]
pub color: Color,
#[structopt(long, short)]
pub no_summary: bool,
#[structopt(long)]
pub allow_warnings: bool,
#[structopt(long, hidden(true))]
pub luacheck: bool,
#[structopt(long, hidden(true))]
pub ranges: bool,
#[structopt(parse(from_os_str), min_values(1), index(1), required(true))]
pub files: Vec<OsString>,
#[structopt(subcommand)]
pub command: Option<Command>,
}
impl Options {
pub fn quiet(&self) -> bool {
match self.display_style {
Some(display_style) => display_style == DisplayStyle::Quiet,
None => self.quiet,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, StructOpt)]
#[structopt(rename_all = "kebab-case")]
#[allow(clippy::enum_variant_names)]
pub enum Command {
#[cfg(feature = "roblox")]
GenerateRobloxStd,
#[cfg(feature = "roblox")]
UpdateRobloxStd,
UpgradeStd {
#[structopt(parse(from_os_str))]
filename: PathBuf,
},
}
arg_enum! {
#[derive(Clone, Copy, Debug)]
pub enum Color {
Always,
Auto,
Never,
}
}
arg_enum! {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum DisplayStyle {
Json,
Json2,
Rich,
Quiet,
}
}
fn get_num_cpus() -> &'static str {
Box::leak(num_cpus::get().to_string().into_boxed_str())
}