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
8 changed files with 63 additions and 22 deletions

View File

@ -10,8 +10,9 @@ use crate::console::StdioConsoleStream;
use super::resolve_guest; use super::resolve_guest;
#[derive(Parser)] #[derive(Parser)]
#[command(about = "Attach to the guest console")]
pub struct AttachCommand { pub struct AttachCommand {
#[arg()] #[arg(help = "Guest to attach to, either the name or the uuid")]
guest: String, guest: String,
} }

View File

@ -17,10 +17,15 @@ use tonic::{transport::Channel, Request};
use crate::cli::resolve_guest; use crate::cli::resolve_guest;
#[derive(Parser)] #[derive(Parser)]
#[command(about = "Destroy a guest")]
pub struct DestroyCommand { pub struct DestroyCommand {
#[arg(short = 'W', long)] #[arg(
short = 'W',
long,
help = "Wait for the destruction of the guest to complete"
)]
wait: bool, wait: bool,
#[arg()] #[arg(help = "Guest to destroy, either the name or the uuid")]
guest: String, guest: String,
} }

View File

@ -22,23 +22,46 @@ use tonic::{transport::Channel, Request};
use crate::console::StdioConsoleStream; use crate::console::StdioConsoleStream;
#[derive(Parser)] #[derive(Parser)]
#[command(about = "Launch a new guest")]
pub struct LauchCommand { pub struct LauchCommand {
#[arg(short, long)] #[arg(short, long, help = "Name of the guest")]
name: Option<String>, 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, 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, mem: u64,
#[arg[short, long]] #[arg[short, long, help = "Environment variables set in the guest"]]
env: Option<Vec<String>>, env: Option<Vec<String>>,
#[arg(short, long)] #[arg(
short,
long,
help = "Attach to the guest after guest starts, implies --wait"
)]
attach: bool, attach: bool,
#[arg(short = 'W', long)] #[arg(
short = 'W',
long,
help = "Wait for the guest to start, implied by --attach"
)]
wait: bool, wait: bool,
#[arg()] #[arg(help = "Container image for guest to use")]
oci: String, oci: String,
#[arg(allow_hyphen_values = true, trailing_var_arg = true)] #[arg(
run: Vec<String>, allow_hyphen_values = true,
trailing_var_arg = true,
help = "Command to run inside the guest"
)]
command: Vec<String>,
} }
impl LauchCommand { impl LauchCommand {
@ -63,7 +86,7 @@ impl LauchCommand {
value: value.clone(), value: value.clone(),
}) })
.collect(), .collect(),
command: self.run, command: self.command,
}), }),
annotations: vec![], annotations: vec![],
}), }),

View File

@ -28,10 +28,11 @@ enum ListFormat {
} }
#[derive(Parser)] #[derive(Parser)]
#[command(about = "List the guests on the hypervisor")]
pub struct ListCommand { pub struct ListCommand {
#[arg(short, long, default_value = "table")] #[arg(short, long, default_value = "table", help = "Output format")]
format: ListFormat, format: ListFormat,
#[arg()] #[arg(help = "Limit to a single guest, either the name or the uuid")]
guest: Option<String>, guest: Option<String>,
} }

View File

@ -15,11 +15,12 @@ use crate::console::StdioConsoleStream;
use super::resolve_guest; use super::resolve_guest;
#[derive(Parser)] #[derive(Parser)]
#[command(about = "View the logs of a guest")]
pub struct LogsCommand { pub struct LogsCommand {
#[arg()] #[arg(short, long, help = "Follow output from the guest")]
guest: String,
#[arg(short, long)]
follow: bool, follow: bool,
#[arg(help = "Guest to show logs for, either the name or the uuid")]
guest: String,
} }
impl LogsCommand { impl LogsCommand {

View File

@ -21,9 +21,17 @@ use self::{
}; };
#[derive(Parser)] #[derive(Parser)]
#[command(version, about)] #[command(
version,
about = "Control the krata hypervisor, a secure platform for running containers"
)]
pub struct ControlCommand { 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, connection: String,
#[command(subcommand)] #[command(subcommand)]

View File

@ -5,8 +5,9 @@ use krata::v1::control::{control_service_client::ControlServiceClient, ResolveGu
use tonic::{transport::Channel, Request}; use tonic::{transport::Channel, Request};
#[derive(Parser)] #[derive(Parser)]
#[command(about = "Resolve a guest name to a uuid")]
pub struct ResolveCommand { pub struct ResolveCommand {
#[arg()] #[arg(help = "Guest name")]
guest: String, guest: String,
} }

View File

@ -17,8 +17,9 @@ enum WatchFormat {
} }
#[derive(Parser)] #[derive(Parser)]
#[command(about = "Watch for guest changes")]
pub struct WatchCommand { pub struct WatchCommand {
#[arg(short, long, default_value = "simple")] #[arg(short, long, default_value = "simple", help = "Output format")]
format: WatchFormat, format: WatchFormat,
} }