From a10ceac5a5ff6de2c85757384e97c273a3038f6c Mon Sep 17 00:00:00 2001 From: tuturuu Date: Sat, 10 Jan 2026 06:46:29 +0100 Subject: Implement Basic CLI skeleton Parse generic commands and subcommands (args) using clap; Write Basic Commands enum docs to show after --help flag. --- vegilctl/src/main.rs | 63 +++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) (limited to 'vegilctl/src') 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); } -- cgit v1.2.3