Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli/stats: Use clap
✗ CI failure Lorenz Leutgeb committed 7 months ago
commit 7823b4eb79c7fd32810a310b5a44f431d375cc3b
parent f1c7c9860716e5db88f657c61d39d6081fb5645f
1 failed (1 total) View logs
3 files changed +14 -41
modified crates/radicle-cli/src/commands/help.rs
@@ -64,7 +64,10 @@ const COMMANDS: &[CommandItem] = &[
    CommandItem::Lexopt(crate::commands::unfollow::HELP),
    CommandItem::Lexopt(crate::commands::unseed::HELP),
    CommandItem::Lexopt(crate::commands::remote::HELP),
-
    CommandItem::Lexopt(crate::commands::stats::HELP),
+
    CommandItem::Clap {
+
        name: "stats",
+
        about: crate::commands::stats::ABOUT,
+
    },
    CommandItem::Lexopt(crate::commands::sync::HELP),
];

modified crates/radicle-cli/src/commands/stats.rs
@@ -1,6 +1,6 @@
-
use std::ffi::OsString;
use std::path::Path;

+
use clap::Parser;
use localtime::LocalDuration;
use localtime::LocalTime;
use radicle::git;
@@ -13,22 +13,8 @@ use radicle_term::Element;
use serde::Serialize;

use crate::terminal as term;
-
use crate::terminal::args::{Args, Error, Help};

-
pub const HELP: Help = Help {
-
    name: "stats",
-
    description: "Displays aggregated repository and node metrics",
-
    version: env!("RADICLE_VERSION"),
-
    usage: r#"
-
Usage
-

-
    rad stats [<option>...]
-

-
Options
-

-
    --help       Print help
-
"#,
-
};
+
pub(crate) const ABOUT: &str = "Displays aggregated repository and node metrics";

#[derive(Default, Serialize)]
#[serde(rename_all = "camelCase")]
@@ -65,30 +51,11 @@ struct Stats {
    nodes: NodeStats,
}

-
#[derive(Default, Debug, Eq, PartialEq)]
-
pub struct Options {}
-

-
impl Args for Options {
-
    fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
-
        use lexopt::prelude::*;
-

-
        let mut parser = lexopt::Parser::from_args(args);
-

-
        #[allow(clippy::never_loop)]
-
        while let Some(arg) = parser.next()? {
-
            match arg {
-
                Long("help") | Short('h') => {
-
                    return Err(Error::Help.into());
-
                }
-
                _ => anyhow::bail!(arg.unexpected()),
-
            }
-
        }
-

-
        Ok((Options {}, vec![]))
-
    }
-
}
+
#[derive(Debug, Parser)]
+
#[command(about = ABOUT, disable_version_flag = true)]
+
pub struct Args {}

-
pub fn run(_options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
+
pub fn run(_options: Args, ctx: impl term::Context) -> anyhow::Result<()> {
    let profile = ctx.profile()?;
    let storage = &profile.storage;
    let mut stats = Stats::default();
modified crates/radicle-cli/src/main.rs
@@ -46,6 +46,7 @@ struct CliArgs {
#[derive(Subcommand, Debug)]
enum Commands {
    Issue(issue::Args),
+
    Stats(stats::Args),
}

#[derive(Debug)]
@@ -283,7 +284,9 @@ fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyhow::Error>>
            term::run_command_args::<remote::Options, _>(remote::HELP, remote::run, args.to_vec())
        }
        "stats" => {
-
            term::run_command_args::<stats::Options, _>(stats::HELP, stats::run, args.to_vec())
+
            if let Some(Commands::Stats(args)) = CliArgs::parse().command {
+
                term::run_command_fn(stats::run, args);
+
            }
        }
        "watch" => {
            term::run_command_args::<watch::Options, _>(watch::HELP, watch::run, args.to_vec())