use std::path::PathBuf;
#[derive(Debug, clap::Args)]
#[command(args_conflicts_with_subcommands = true)]
pub struct DogsArgs {
#[arg(long)]
pub available: bool,
#[arg(long, requires = "available")]
pub refresh: bool,
#[arg(value_name = "FILTER")]
pub filter: Option<String>,
#[command(subcommand)]
pub command: Option<DogsCommand>,
}
#[derive(Debug, clap::Subcommand)]
pub enum DogsCommand {
Grant(GrantArgs),
Revoke(GrantArgs),
}
#[derive(Debug, clap::Args)]
pub struct GrantArgs {
pub name: String,
pub permission: String,
}
#[derive(Debug, clap::Args)]
pub struct DogArgs {
pub name: String,
}
#[derive(Debug, clap::Args)]
pub struct EnableArgs {
pub name: String,
#[arg(long, hide = true)]
pub exec: Option<PathBuf>,
#[arg(long)]
pub yes: bool,
}
#[derive(Debug, clap::Args)]
pub struct DisableArgs {
pub name: String,
}
#[derive(Debug, clap::Args)]
pub struct AdoptArgs {
pub path: PathBuf,
#[arg(long)]
pub name: Option<String>,
#[arg(long)]
pub yes: bool,
}
#[derive(Debug, clap::Args)]
pub struct InstallArgs {
pub dog: Option<String>,
#[arg(long)]
pub yes: bool,
#[arg(long)]
pub no_enable: bool,
#[arg(long)]
pub refresh: bool,
#[arg(long)]
pub cargo: bool,
#[arg(
long = "ref",
value_name = "REF",
requires = "dog",
conflicts_with = "cargo"
)]
pub git_ref: Option<String>,
}
#[derive(Debug, clap::Args)]
pub struct UpgradeArgs {
#[arg(conflicts_with = "all")]
pub dog: Option<String>,
#[arg(long = "dogs", id = "all")]
pub all: bool,
#[arg(
long = "ref",
value_name = "REF",
requires = "dog",
conflicts_with_all = ["release", "rollback"]
)]
pub git_ref: Option<String>,
#[arg(long, requires = "dog", conflicts_with = "rollback")]
pub release: bool,
#[arg(long, requires = "dog")]
pub rollback: bool,
#[arg(long)]
pub refresh: bool,
}
#[cfg(test)]
mod tests {
use crate::cli::{Cli, Commands};
#[test]
fn the_dog_subcommand_parses_and_stays_hidden() {
use clap::{CommandFactory, Parser};
let parsed = Cli::try_parse_from(["shep", "dog", "metrics"])
.unwrap()
.command;
let Commands::Dog(args) = parsed else {
panic!("expected dog")
};
assert_eq!(args.name, "metrics");
let cmd = Cli::command();
assert!(
cmd.find_subcommand("dog").unwrap().is_hide_set(),
"dog must stay hidden from --help"
);
}
#[test]
fn the_exec_alias_stays_hidden_from_help() {
use clap::CommandFactory;
let cmd = Cli::command();
let enable = cmd.find_subcommand("enable").unwrap();
let exec_arg = enable
.get_arguments()
.find(|a| a.get_id().as_str() == "exec")
.expect("EnableArgs must still carry a hidden `exec` field");
assert!(
exec_arg.is_hide_set(),
"--exec must stay hidden from --help"
);
}
}