Skip to content

Commit

Permalink
with procs
Browse files Browse the repository at this point in the history
  • Loading branch information
kjuulh committed Dec 18, 2022
1 parent af12f2b commit db6f234
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/stats/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod code;
mod network;
mod procs;

pub struct Stats;

Expand All @@ -12,7 +13,11 @@ impl Stats {
impl util::Cmd for Stats {
fn cmd() -> eyre::Result<clap::Command> {
let cmd = clap::Command::new("stats")
.subcommands(&[code::Code::cmd()?, network::Network::cmd()?])
.subcommands(&[
code::Code::cmd()?,
network::Network::cmd()?,
procs::Procs::cmd()?,
])
.subcommand_required(true);

Ok(cmd)
Expand All @@ -22,6 +27,7 @@ impl util::Cmd for Stats {
match args.subcommand() {
Some(("code", args)) => code::Code::exec(args),
Some(("network", args)) => network::Network::exec(args),
Some(("procs", args)) => procs::Procs::exec(args),
_ => Stats::run(),
}
}
Expand Down
29 changes: 29 additions & 0 deletions crates/stats/src/procs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pub struct Procs;

impl Procs {
fn run() -> eyre::Result<()> {
if let Err(_) = util::shell::run_with_input_and_output(&["procs", "--version"], "".into()) {
return Err(eyre::anyhow!(
"could not find procs, please install or add to PATH"
));
}

util::shell::run(&["procs"], None)?;

Ok(())
}
}

impl util::Cmd for Procs {
fn cmd() -> eyre::Result<clap::Command> {
let cmd = clap::Command::new("procs").subcommands(&[]);

Ok(cmd)
}

fn exec(args: &clap::ArgMatches) -> eyre::Result<()> {
match args.subcommand() {
_ => Procs::run(),
}
}
}

0 comments on commit db6f234

Please sign in to comment.