use std::path::PathBuf;
use clap::{Args, Parser, Subcommand, ValueEnum};
#[derive(Debug, Parser)]
#[command(
name = "opy-cli",
disable_version_flag = true,
disable_help_subcommand = true,
subcommand_precedence_over_arg = true,
about = "Workshop-independent OPY tooling",
after_help = EXIT_CODES
)]
pub(crate) struct Cli {
#[command(subcommand)]
pub(crate) command: Option<Command>,
#[arg(short = 'V', long, global = true, action = clap::ArgAction::SetTrue)]
pub(crate) version: bool,
#[arg(long, global = true, value_enum, default_value_t = RendererArg::Auto)]
pub(crate) renderer: RendererArg,
#[arg(long, global = true, value_enum, default_value_t = ColorArg::Auto)]
pub(crate) color: ColorArg,
}
pub(crate) const EXIT_CODES: &str = "EXIT CODES:
0 clean or successful operation
1 source diagnostics
2 usage or I/O error";
#[derive(Debug, Subcommand)]
pub(crate) enum Command {
Check(CheckArgs),
Compile(CompileArgs),
Inspect(FileArgs),
Support(SupportArgs),
Completion(CompletionArgs),
Help,
Version,
}
#[derive(Debug, Args)]
pub(crate) struct CheckArgs {
#[command(flatten)]
pub(crate) file: FileArgs,
#[arg(long, value_enum, default_value_t = OutputFormatArg::Text)]
pub(crate) format: OutputFormatArg,
}
#[derive(Debug, Args)]
pub(crate) struct CompileArgs {
#[command(flatten)]
pub(crate) file: FileArgs,
#[arg(long, value_enum, default_value_t = OutputFormatArg::Text)]
pub(crate) format: OutputFormatArg,
#[arg(long, default_value = "en-US", value_name = "LOCALE")]
pub(crate) language: String,
}
#[derive(Debug, Args)]
pub(crate) struct FileArgs {
#[arg(value_name = "MAIN.OPY")]
pub(crate) main: PathBuf,
}
#[derive(Debug, Args)]
pub(crate) struct SupportArgs {
#[arg(long)]
pub(crate) json: bool,
#[arg(value_name = "CATEGORY|FEATURE-ID")]
pub(crate) filter: Option<String>,
}
#[derive(Debug, Args)]
pub(crate) struct CompletionArgs {
#[arg(value_enum, value_name = "SHELL")]
pub(crate) shell: ShellArg,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub(crate) enum RendererArg {
Auto,
Terminal,
Plain,
#[value(name = "github-actions", alias = "github")]
GithubActions,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub(crate) enum ColorArg {
Auto,
Always,
Never,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub(crate) enum OutputFormatArg {
Text,
#[value(alias = "machine")]
Json,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub(crate) enum ShellArg {
Bash,
Zsh,
Fish,
#[value(name = "powershell", alias = "pwsh")]
PowerShell,
}