use crate::os::ExecutableCommand;
use anyhow::Result;
use clap::{Args, Parser, Subcommand, ValueHint};
use clap_complete::Shell;
#[derive(clap::ValueEnum, Clone, Copy, Debug, serde::Serialize, serde::Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum OutputFormat {
Table,
Json,
Yaml,
Original,
}
#[derive(Parser)]
#[command(
name = "ao",
version = env!("CARGO_PKG_VERSION"),
about = "Admin Operation",
long_about = "A unified administration tool for Linux systems, providing a consistent interface for managing packages, services, users, networking, and more across various distributions."
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<CliCommand>,
#[arg(global = true, long, hide = true)]
pub print: bool,
#[arg(global = true, long, hide = true)]
pub dry_run: bool,
#[arg(global = true, long, hide = true)]
pub dump_tree: bool,
}
#[derive(Subcommand)]
pub enum CliCommand {
Interactive,
}
#[derive(Args)]
pub struct MonitorArgs {
#[arg(long, short, default_value = "table")]
pub format: OutputFormat,
}
#[derive(Args)]
pub struct PkgArgs {
#[command(subcommand)]
pub action: Option<PkgAction>,
}
#[derive(Subcommand)]
pub enum PkgAction {
Add {
#[arg(required = true, value_hint = ValueHint::Other)]
packages: Vec<String>,
},
Ls {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Del {
#[arg(required = true, value_hint = ValueHint::Other)]
packages: Vec<String>,
#[arg(long, short)]
purge: bool,
},
Search {
#[arg(required = true, value_hint = ValueHint::Other)]
query: String,
},
Update,
}
#[derive(Args)]
pub struct SvcArgs {
#[command(subcommand)]
pub action: Option<SvcAction>,
}
#[derive(Subcommand)]
pub enum SvcAction {
Down {
#[arg(required = true, value_hint = ValueHint::Other)]
name: String,
},
Ls {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Reload {
#[arg(required = true, value_hint = ValueHint::Other)]
name: String,
},
Restart {
#[arg(required = true, value_hint = ValueHint::Other)]
name: String,
},
Status {
#[arg(required = true, value_hint = ValueHint::Other)]
name: String,
},
Up {
#[arg(required = true, value_hint = ValueHint::Other)]
name: String,
},
}
#[derive(Args)]
pub struct UserArgs {
#[command(subcommand)]
pub action: Option<UserAction>,
}
#[derive(Subcommand)]
pub enum UserAction {
Add {
#[arg(required = true, value_hint = ValueHint::Other)]
username: String,
#[arg(long, value_hint = ValueHint::Other)]
name: Option<String>,
#[arg(long, value_hint = ValueHint::Other)]
email: Option<String>,
#[arg(long, value_hint = ValueHint::Other)]
groups: Option<String>,
#[arg(long, value_hint = ValueHint::Other)]
shell: Option<String>,
#[arg(long)]
system: bool,
#[arg(long)]
no_create_home: bool,
},
Del {
#[arg(required = true, value_hint = ValueHint::Other)]
username: String,
#[arg(long, short)]
purge: bool,
},
Ls {
#[arg(long)]
all: bool,
#[arg(long)]
groups: bool,
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Mod {
#[arg(required = true, value_hint = ValueHint::Other)]
username: String,
#[arg(required = true)]
action: String,
#[arg(required = true)]
value: String,
},
Passwd {
#[arg(required = true, value_hint = ValueHint::Other)]
username: String,
},
}
#[derive(Args)]
pub struct GroupArgs {
#[command(subcommand)]
pub action: Option<GroupAction>,
}
#[derive(Subcommand)]
pub enum GroupAction {
Add {
#[arg(required = true, value_hint = ValueHint::Other)]
groupname: String,
},
Del {
#[arg(required = true, value_hint = ValueHint::Other)]
groupname: String,
},
Ls {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Mod {
#[arg(required = true, value_hint = ValueHint::Other)]
groupname: String,
#[arg(long)]
gid: u32,
},
}
#[derive(Args)]
pub struct DiskArgs {
#[command(subcommand)]
pub action: Option<DiskAction>,
}
impl DiskArgs {
pub fn run(
&self,
_system: &crate::os::detector::DetectedSystem,
) -> Result<Box<dyn ExecutableCommand>> {
anyhow::bail!("DiskArgs::run is no longer used in the unified Domain architecture")
}
}
#[derive(Subcommand)]
pub enum DiskAction {
Ls {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Mount {
#[arg(required = true, value_hint = ValueHint::Other)]
device: String,
#[arg(required = true, value_hint = ValueHint::DirPath)]
path: String,
#[arg(long, short)]
fstype: Option<String>,
#[arg(long, short)]
options: Option<String>,
},
Unmount {
#[arg(required = true, value_hint = ValueHint::Other)]
target: String,
#[arg(long, short)]
lazy: bool,
#[arg(long, short)]
force: bool,
},
Usage {
#[arg(required = true, value_hint = ValueHint::DirPath)]
path: String,
#[arg(long)]
depth: Option<u32>,
},
}
#[derive(Args)]
pub struct SysArgs {
#[command(subcommand)]
pub action: Option<SysAction>,
}
#[derive(Subcommand)]
pub enum SysAction {
Info {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Power {
#[arg(required = true)]
state: String,
#[arg(long)]
now: bool,
#[arg(long)]
force: bool,
},
Time {
#[arg(required = true)]
action: String,
value: Option<String>,
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
}
#[derive(Args)]
pub struct LogArgs {
#[command(subcommand)]
pub action: Option<LogAction>,
}
#[derive(Subcommand)]
pub enum LogAction {
Auth {
#[arg(long, short, default_value = "50")]
lines: u32,
#[arg(long, short)]
follow: bool,
},
Boot {
#[arg(long, short, default_value = "50")]
lines: u32,
#[arg(long, short)]
follow: bool,
#[arg(long)]
id: Option<String>,
},
Crash {
#[arg(long, short, default_value = "50")]
lines: u32,
},
Dev {
#[arg(long, short, default_value = "50")]
lines: u32,
#[arg(long, short)]
follow: bool,
},
Error {
#[arg(long, short, default_value = "50")]
lines: u32,
#[arg(long, short)]
follow: bool,
},
File {
#[arg(required = true, value_hint = ValueHint::FilePath)]
path: String,
#[arg(long, short, default_value = "50")]
lines: u32,
#[arg(long, short)]
follow: bool,
},
Pkg {
#[arg(long, short, default_value = "50")]
lines: u32,
},
Svc {
#[arg(required = true, value_hint = ValueHint::Other)]
name: String,
#[arg(long, short, default_value = "50")]
lines: u32,
#[arg(long, short)]
follow: bool,
},
Sys {
#[arg(long, short, default_value = "50")]
lines: u32,
#[arg(long, short)]
follow: bool,
},
}
#[derive(Args)]
pub struct DistroArgs {
#[command(subcommand)]
pub action: Option<DistroAction>,
}
#[derive(Subcommand)]
pub enum DistroAction {
Info {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Upgrade,
}
#[derive(Args)]
pub struct NetArgs {
#[command(subcommand)]
pub action: Option<NetAction>,
}
#[derive(Subcommand)]
pub enum NetAction {
Interfaces {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Ips {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Routes {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Fw {
#[command(subcommand)]
action: FwAction,
},
Wifi {
#[command(subcommand)]
action: WifiAction,
},
}
#[derive(Subcommand)]
pub enum FwAction {
Status {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Allow { rule: String },
Deny { rule: String },
}
#[derive(Subcommand)]
pub enum WifiAction {
Scan,
Connect { ssid: String },
}
#[derive(Args)]
pub struct BootArgs {
#[command(subcommand)]
pub action: Option<BootAction>,
}
#[derive(Subcommand)]
pub enum BootAction {
Ls {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Mod {
#[command(subcommand)]
action: BootModAction,
},
}
#[derive(Subcommand)]
pub enum BootModAction {
Ls {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Load { name: String },
Unload { name: String },
}
#[derive(Args)]
pub struct GuiArgs {
#[command(subcommand)]
pub action: Option<GuiAction>,
}
#[derive(Subcommand)]
pub enum GuiAction {
Info,
Display {
#[command(subcommand)]
action: GuiDisplayAction,
},
}
#[derive(Subcommand)]
pub enum GuiDisplayAction {
Ls {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
}
#[derive(Args)]
pub struct DevArgs {
#[command(subcommand)]
pub action: Option<DevAction>,
}
#[derive(Subcommand)]
pub enum DevAction {
Ls {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Pci {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Usb {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Bt {
#[command(subcommand)]
action: BtAction,
},
Print {
#[command(subcommand)]
action: PrintAction,
},
}
#[derive(Subcommand)]
pub enum BtAction {
Status,
Scan,
Pair { address: String },
Connect { address: String },
}
#[derive(Subcommand)]
pub enum PrintAction {
Ls {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
}
#[derive(Args)]
pub struct VirtArgs {
#[command(subcommand)]
pub action: Option<VirtAction>,
}
#[derive(Subcommand)]
pub enum VirtAction {
Ls {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Start { name: String },
Stop { name: String },
Rm { name: String },
Logs { name: String },
}
#[derive(Args)]
pub struct SecArgs {
#[command(subcommand)]
pub action: Option<SecAction>,
}
#[derive(Subcommand)]
pub enum SecAction {
Audit {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Context,
}
#[derive(Args)]
pub struct SelfArgs {
#[command(subcommand)]
pub action: Option<SelfAction>,
}
#[derive(Subcommand)]
pub enum SelfAction {
Completions {
#[command(subcommand)]
action: CompletionsAction,
},
Info {
#[arg(long, short, default_value = "table")]
format: OutputFormat,
},
Update,
}
#[derive(Subcommand)]
pub enum CompletionsAction {
Generate {
shell: Shell,
},
Install {
shell: Shell,
},
Setup {
shell: Shell,
},
}