feat(ctl): add help and about to commands and arguments (#25)

This commit is contained in:
Alex Zenla 2024-04-05 17:00:02 -07:00 committed by GitHub
parent 2f3daad80a
commit f2ab03711e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 63 additions and 22 deletions

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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<String>,
#[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<Vec<String>>,
#[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<String>,
#[arg(
allow_hyphen_values = true,
trailing_var_arg = true,
help = "Command to run inside the guest"
)]
command: Vec<String>,
}
impl LauchCommand {
@ -63,7 +86,7 @@ impl LauchCommand {
value: value.clone(),
})
.collect(),
command: self.run,
command: self.command,
}),
annotations: vec![],
}),

View File

@ -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<String>,
}

View File

@ -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 {

View File

@ -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)]

View File

@ -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,
}

View File

@ -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,
}