diff options
| author | tuturuu <zedddiezxc@gmail.com> | 2026-01-10 06:46:29 +0100 |
|---|---|---|
| committer | tuturuu <zedddiezxc@gmail.com> | 2026-01-10 06:46:29 +0100 |
| commit | a10ceac5a5ff6de2c85757384e97c273a3038f6c (patch) | |
| tree | 596eb71d5cd06b2d08f5193f0ab0d5ff9a190e7a /vegilctl/src | |
| parent | 0b7e289f2287bc25e8b619b2fda2cef26373a5c9 (diff) | |
Implement Basic CLI skeleton
Parse generic commands and subcommands (args) using clap; Write Basic
Commands enum docs to show after
--help flag.
Diffstat (limited to 'vegilctl/src')
| -rw-r--r-- | vegilctl/src/main.rs | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/vegilctl/src/main.rs b/vegilctl/src/main.rs index cbfc2f2..08ff37c 100644 --- a/vegilctl/src/main.rs +++ b/vegilctl/src/main.rs @@ -1,37 +1,40 @@ -#[derive(Debug)] +use clap::{Parser, Subcommand}; + +#[derive(Subcommand, Clone,Debug)] enum Command { - Status, - Stop, - Start, - Enable, - Disable, + /// Check Service Status + Status { of: String }, + /// Stop Specified Service + Stop { service: String }, + /// Start Specified Service + Start { service: String }, + /// Start Service after system initialization (Add Service symlink to Vigil service startup + /// list) + Enable { service: String }, + /// Remove Service From Service initialization list + Disable { service: String }, + /// Power Management Commands + #[command(subcommand)] + Power(PowerCommand) +} +#[derive(Subcommand, Clone, Debug)] +enum PowerCommand { + /// Reboot System + Reboot, + /// Poweroff System + Poweroff, + /// Halt + Halt } -struct CliArgs { +#[derive(Parser)] +#[command(name = "vigilctl")] +#[command(about = "Vigil control manager")] +struct Cli { + #[command(subcommand)] command: Command, - target: String } fn main() { - let command:Command = match std::env::args().nth(1).as_deref(){ - Some("status") => Command::Status, - Some("start") => Command::Start, - Some("stop") => Command::Stop, - Some("enable") => Command::Enable, - Some("disable") => Command::Disable, - Some(cmd) => { - eprintln!("invalid command arg:{}", cmd); - std::process::exit(1); - } - None => { - eprintln!("Invalid input: No command arg specified\nRun with --help to get help"); - std::process::exit(1); - } - }; - let target = std::env::args().nth(2).expect("no target arg specified"); - - let args = CliArgs { - command, - target - }; + let args = Cli::parse(); - println!("command: {:?}, target: {:?}", args.command, args.target); + println!("command: {:?}", args.command); } |
