summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vegilctl/src/main.rs63
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);
}