From f2ab03711ef9e4fca0016f8862a886090cf02661 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Fri, 5 Apr 2024 17:00:02 -0700 Subject: [PATCH] feat(ctl): add help and about to commands and arguments (#25) --- crates/ctl/src/cli/attach.rs | 3 ++- crates/ctl/src/cli/destroy.rs | 9 ++++++-- crates/ctl/src/cli/launch.rs | 43 +++++++++++++++++++++++++++-------- crates/ctl/src/cli/list.rs | 5 ++-- crates/ctl/src/cli/logs.rs | 7 +++--- crates/ctl/src/cli/mod.rs | 12 ++++++++-- crates/ctl/src/cli/resolve.rs | 3 ++- crates/ctl/src/cli/watch.rs | 3 ++- 8 files changed, 63 insertions(+), 22 deletions(-) diff --git a/crates/ctl/src/cli/attach.rs b/crates/ctl/src/cli/attach.rs index 4d57177..24c10f4 100644 --- a/crates/ctl/src/cli/attach.rs +++ b/crates/ctl/src/cli/attach.rs @@ -10,8 +10,9 @@ use crate::console::StdioConsoleStream; use super::resolve_guest; #[derive(Parser)] +#[command(about = "Attach to the guest console")] pub struct AttachCommand { - #[arg()] + #[arg(help = "Guest to attach to, either the name or the uuid")] guest: String, } diff --git a/crates/ctl/src/cli/destroy.rs b/crates/ctl/src/cli/destroy.rs index d6fd9b3..869b228 100644 --- a/crates/ctl/src/cli/destroy.rs +++ b/crates/ctl/src/cli/destroy.rs @@ -17,10 +17,15 @@ use tonic::{transport::Channel, Request}; use crate::cli::resolve_guest; #[derive(Parser)] +#[command(about = "Destroy a guest")] pub struct DestroyCommand { - #[arg(short = 'W', long)] + #[arg( + short = 'W', + long, + help = "Wait for the destruction of the guest to complete" + )] wait: bool, - #[arg()] + #[arg(help = "Guest to destroy, either the name or the uuid")] guest: String, } diff --git a/crates/ctl/src/cli/launch.rs b/crates/ctl/src/cli/launch.rs index 5f3e607..672b00d 100644 --- a/crates/ctl/src/cli/launch.rs +++ b/crates/ctl/src/cli/launch.rs @@ -22,23 +22,46 @@ use tonic::{transport::Channel, Request}; use crate::console::StdioConsoleStream; #[derive(Parser)] +#[command(about = "Launch a new guest")] pub struct LauchCommand { - #[arg(short, long)] + #[arg(short, long, help = "Name of the guest")] name: Option, - #[arg(short, long, default_value_t = 1)] + #[arg( + short, + long, + default_value_t = 1, + help = "vCPUs available to the guest" + )] cpus: u32, - #[arg(short, long, default_value_t = 512)] + #[arg( + short, + long, + default_value_t = 512, + help = "Memory available to the guest, in megabytes" + )] mem: u64, - #[arg[short, long]] + #[arg[short, long, help = "Environment variables set in the guest"]] env: Option>, - #[arg(short, long)] + #[arg( + short, + long, + help = "Attach to the guest after guest starts, implies --wait" + )] attach: bool, - #[arg(short = 'W', long)] + #[arg( + short = 'W', + long, + help = "Wait for the guest to start, implied by --attach" + )] wait: bool, - #[arg()] + #[arg(help = "Container image for guest to use")] oci: String, - #[arg(allow_hyphen_values = true, trailing_var_arg = true)] - run: Vec, + #[arg( + allow_hyphen_values = true, + trailing_var_arg = true, + help = "Command to run inside the guest" + )] + command: Vec, } impl LauchCommand { @@ -63,7 +86,7 @@ impl LauchCommand { value: value.clone(), }) .collect(), - command: self.run, + command: self.command, }), annotations: vec![], }), diff --git a/crates/ctl/src/cli/list.rs b/crates/ctl/src/cli/list.rs index 8388949..f146a05 100644 --- a/crates/ctl/src/cli/list.rs +++ b/crates/ctl/src/cli/list.rs @@ -28,10 +28,11 @@ enum ListFormat { } #[derive(Parser)] +#[command(about = "List the guests on the hypervisor")] pub struct ListCommand { - #[arg(short, long, default_value = "table")] + #[arg(short, long, default_value = "table", help = "Output format")] format: ListFormat, - #[arg()] + #[arg(help = "Limit to a single guest, either the name or the uuid")] guest: Option, } diff --git a/crates/ctl/src/cli/logs.rs b/crates/ctl/src/cli/logs.rs index 17b9e9f..33a794a 100644 --- a/crates/ctl/src/cli/logs.rs +++ b/crates/ctl/src/cli/logs.rs @@ -15,11 +15,12 @@ use crate::console::StdioConsoleStream; use super::resolve_guest; #[derive(Parser)] +#[command(about = "View the logs of a guest")] pub struct LogsCommand { - #[arg()] - guest: String, - #[arg(short, long)] + #[arg(short, long, help = "Follow output from the guest")] follow: bool, + #[arg(help = "Guest to show logs for, either the name or the uuid")] + guest: String, } impl LogsCommand { diff --git a/crates/ctl/src/cli/mod.rs b/crates/ctl/src/cli/mod.rs index 26fea9e..0b9f220 100644 --- a/crates/ctl/src/cli/mod.rs +++ b/crates/ctl/src/cli/mod.rs @@ -21,9 +21,17 @@ use self::{ }; #[derive(Parser)] -#[command(version, about)] +#[command( + version, + about = "Control the krata hypervisor, a secure platform for running containers" +)] pub struct ControlCommand { - #[arg(short, long, default_value = "unix:///var/lib/krata/daemon.socket")] + #[arg( + short, + long, + help = "The connection URL to the krata hypervisor", + default_value = "unix:///var/lib/krata/daemon.socket" + )] connection: String, #[command(subcommand)] diff --git a/crates/ctl/src/cli/resolve.rs b/crates/ctl/src/cli/resolve.rs index 05f3b2e..4ed3a39 100644 --- a/crates/ctl/src/cli/resolve.rs +++ b/crates/ctl/src/cli/resolve.rs @@ -5,8 +5,9 @@ use krata::v1::control::{control_service_client::ControlServiceClient, ResolveGu use tonic::{transport::Channel, Request}; #[derive(Parser)] +#[command(about = "Resolve a guest name to a uuid")] pub struct ResolveCommand { - #[arg()] + #[arg(help = "Guest name")] guest: String, } diff --git a/crates/ctl/src/cli/watch.rs b/crates/ctl/src/cli/watch.rs index 6b7218f..81c736b 100644 --- a/crates/ctl/src/cli/watch.rs +++ b/crates/ctl/src/cli/watch.rs @@ -17,8 +17,9 @@ enum WatchFormat { } #[derive(Parser)] +#[command(about = "Watch for guest changes")] pub struct WatchCommand { - #[arg(short, long, default_value = "simple")] + #[arg(short, long, default_value = "simple", help = "Output format")] format: WatchFormat, }