From aa3b529f3f23275ff14a222401af80d63e293697 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 28 Apr 2021 14:06:30 +0200 Subject: Add subcommand to get top output of containers Signed-off-by: Matthias Beyer --- src/cli.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/cli.rs') diff --git a/src/cli.rs b/src/cli.rs index 49c3caa..94187da 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -9,6 +9,7 @@ // use std::path::PathBuf; +use std::str::FromStr; use clap::crate_authors; use clap::crate_version; @@ -1043,6 +1044,26 @@ pub fn cli<'a>() -> App<'a> { .conflicts_with("older_than") ) ) + .subcommand(App::new("top") + .version(crate_version!()) + .about("List the processes of all containers") + .arg(Arg::new("csv") + .required(false) + .multiple(false) + .long("csv") + .takes_value(false) + .about("List top output as CSV") + ) + .arg(Arg::new("limit") + .required(false) + .multiple(false) + .long("limit") + .takes_value(true) + .value_name("LIMIT") + .about("Only list LIMIT processes for each container") + .validator(parse_usize) + ) + ) ) .subcommand(App::new("container") .version(crate_version!()) @@ -1205,6 +1226,10 @@ fn parse_date_from_string(s: &str) -> std::result::Result<(), String> { humantime::parse_rfc3339_weak(s).map_err(|e| e.to_string()).map(|_| ()) } +fn parse_usize(s: &str) -> std::result::Result<(), String> { + usize::from_str(s) .map_err(|e| e.to_string()).map(|_| ()) +} + #[cfg(test)] mod tests { use super::env_pass_validator; -- cgit v1.2.3