use clap::{CommandFactory, FromArgMatches, Parser, Subcommand};
use clap_complete::Shell;
#[derive(Parser, Debug)]
#[command(
name = "fez",
version,
about = "Agent-native management CLI for Fedora/RHEL"
)]
pub struct Cli {
#[arg(long, global = true)]
pub host: Option<String>,
#[arg(long, global = true)]
pub json: bool,
#[arg(long, global = true)]
pub dry_run: bool,
#[arg(long, global = true)]
pub force: bool,
#[command(subcommand)]
pub command: TopCommand,
}
pub fn raw_command() -> clap::Command {
<Cli as CommandFactory>::command()
}
pub fn command() -> clap::Command {
crate::capability::help::inject(raw_command())
}
pub fn parse() -> Cli {
let matches = command().get_matches();
Cli::from_arg_matches(&matches).expect("clap validated args")
}
#[derive(Subcommand, Debug)]
pub enum TopCommand {
Capabilities,
Describe {
capability: String,
},
Guide,
Completions {
#[arg(value_enum)]
shell: Shell,
},
#[command(hide = true)]
Man,
Services {
#[command(subcommand)]
action: ServicesAction,
},
Mcp,
}
#[derive(Subcommand, Debug)]
pub enum ServicesAction {
List {
#[arg(long)]
state: Option<String>,
},
Status {
unit: String,
},
Logs {
unit: String,
#[arg(long)]
since: Option<String>,
#[arg(long)]
priority: Option<String>,
#[arg(long)]
lines: Option<u32>,
#[arg(long)]
follow: bool,
},
Start {
unit: String,
},
Stop {
unit: String,
},
Restart {
unit: String,
},
Reload {
unit: String,
},
Enable {
unit: String,
#[arg(long)]
now: bool,
},
Disable {
unit: String,
#[arg(long)]
now: bool,
},
}