summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs207
1 files changed, 207 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
index bc59171..22aae6d 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -837,6 +837,209 @@ pub fn cli<'a>() -> App<'a> {
.version(crate_version!())
.about("Print metrics about butido")
)
+
+ .subcommand(App::new("endpoint")
+ .version(crate_version!())
+ .about("Endpoint maintentance commands")
+ .arg(Arg::new("endpoint_name")
+ .required(false)
+ .multiple(false)
+ .index(1)
+ .value_name("ENDPOINT_NAME")
+ .about("Endpoint to talk to, or all if not given")
+ )
+
+ .subcommand(App::new("ping")
+ .version(crate_version!())
+ .about("Ping the endpoint(s)")
+ .arg(Arg::new("ping_n")
+ .required(false)
+ .multiple(false)
+ .long("times")
+ .short('n')
+ .value_name("N")
+ .default_value("10")
+ .about("How often to ping")
+ )
+ .arg(Arg::new("ping_sleep")
+ .required(false)
+ .multiple(false)
+ .long("sleep")
+ .value_name("N")
+ .default_value("1")
+ .about("How long to sleep between pings")
+ )
+ )
+ .subcommand(App::new("stats")
+ .version(crate_version!())
+ .about("Get stats for the endpoint(s)")
+ .arg(Arg::new("csv")
+ .required(false)
+ .multiple(false)
+ .long("csv")
+ .takes_value(false)
+ .about("Format output as CSV")
+ )
+ )
+ .subcommand(App::new("containers")
+ .version(crate_version!())
+ .about("Work with the containers of the endpoint(s)")
+ .subcommand(App::new("prune")
+ .version(crate_version!())
+ .about("Remove exited containers")
+ .arg(Arg::new("older_than")
+ .required(false)
+ .multiple(false)
+ .long("older-than")
+ .takes_value(true)
+ .value_name("DATE")
+ .about("List only containers that are older than DATE")
+ .validator(parse_date_from_string)
+ .conflicts_with("newer_than")
+ )
+
+ .arg(Arg::new("newer_than")
+ .required(false)
+ .multiple(false)
+ .long("newer-than")
+ .takes_value(true)
+ .value_name("DATE")
+ .about("List only containers that are newer than DATE")
+ .validator(parse_date_from_string)
+ .conflicts_with("older_than")
+ )
+ )
+ .subcommand(App::new("list")
+ .version(crate_version!())
+ .about("List the containers and stats about them")
+ .arg(Arg::new("csv")
+ .required(false)
+ .multiple(false)
+ .long("csv")
+ .takes_value(false)
+ .about("Format output as CSV")
+ )
+
+ .arg(Arg::new("list_stopped")
+ .required(false)
+ .multiple(false)
+ .long("list-stopped")
+ .takes_value(false)
+ .about("List stopped containers too")
+ )
+
+ .arg(Arg::new("filter_image")
+ .required(false)
+ .multiple(false)
+ .long("image")
+ .takes_value(true)
+ .value_name("IMAGE")
+ .about("List only containers of IMAGE")
+ )
+
+ .arg(Arg::new("older_than")
+ .required(false)
+ .multiple(false)
+ .long("older-than")
+ .takes_value(true)
+ .value_name("DATE")
+ .about("List only containers that are older than DATE")
+ .validator(parse_date_from_string)
+ .conflicts_with("newer_than")
+ )
+
+ .arg(Arg::new("newer_than")
+ .required(false)
+ .multiple(false)
+ .long("newer-than")
+ .takes_value(true)
+ .value_name("DATE")
+ .about("List only containers that are newer than DATE")
+ .validator(parse_date_from_string)
+ .conflicts_with("older_than")
+ )
+ )
+ )
+ .subcommand(App::new("container")
+ .version(crate_version!())
+ .about("Work with a specific container")
+ .arg(Arg::new("container_id")
+ .required(true)
+ .multiple(false)
+ .index(1)
+ .takes_value(true)
+ .value_name("CONTAINER_ID")
+ .about("Work with container CONTAINER_ID")
+ )
+ .subcommand(App::new("top")
+ .version(crate_version!())
+ .about("List the container processes")
+ .arg(Arg::new("csv")
+ .required(false)
+ .multiple(false)
+ .long("csv")
+ .takes_value(false)
+ .about("List top output as CSV")
+ )
+ )
+ .subcommand(App::new("kill")
+ .version(crate_version!())
+ .about("Kill the container")
+ .arg(Arg::new("signal")
+ .required(false)
+ .multiple(false)
+ .index(1)
+ .takes_value(true)
+ .value_name("SIGNAL")
+ .about("Kill container with this signal")
+ )
+ )
+ .subcommand(App::new("delete")
+ .version(crate_version!())
+ .about("Delete the container")
+ )
+ .subcommand(App::new("start")
+ .version(crate_version!())
+ .about("Start the container")
+ )
+ .subcommand(App::new("stop")
+ .version(crate_version!())
+ .about("Stop the container")
+ .arg(Arg::new("timeout")
+ .required(false)
+ .multiple(false)
+ .long("timeout")
+ .takes_value(true)
+ .value_name("DURATION")
+ .about("Timeout")
+ )
+ )
+ .subcommand(App::new("exec")
+ .version(crate_version!())
+ .about("Execute commands in the container")
+ .arg(Arg::new("commands")
+ .required(true)
+ .multiple(true)
+ .index(1)
+ .takes_value(true)
+ .value_name("CMD")
+ .about("Commands to execute in the container")
+ .long_about(indoc::indoc!(r#"
+ Execute a command in the container.
+
+ This does not handle TTY forwarding, so you cannot execute interactive commands in the container (e.g. htop).
+ For executing interactive things, you have to login to the container.
+ "#))
+ )
+ )
+
+ .subcommand(App::new("inspect")
+ .version(crate_version!())
+ .about("Display details about the container")
+ .long_about("Display details about the container. Do not assume the output format to be stable.")
+ )
+ )
+ )
}
fn script_arg_line_numbers<'a>() -> clap::Arg<'a> {
@@ -914,6 +1117,10 @@ fn dir_exists_validator(s: &str) -> Result<(), String> {
}
}
+fn parse_date_from_string(s: &str) -> std::result::Result<(), String> {
+ humantime::parse_rfc3339_weak(s).map_err(|e| e.to_string()).map(|_| ())
+}
+
#[cfg(test)]
mod tests {
use super::env_pass_validator;