Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
cli/debug: Use clap
Merged lorenz opened 7 months ago

See issue/7fb03f234030b91c38cc4f5b48bd30cf5fd6a1de.

5 files changed +28 -31 2e77d5ef 7c89045e
modified crates/radicle-cli/examples/rad-help.md
@@ -11,6 +11,7 @@ Common `rad` commands used in various situations:
	checkout     Checkout a repository into the local directory
	clone        Clone a Radicle repository
	config       Manage your local Radicle configuration
+
	debug        Write out information to help debug your Radicle node remotely
	fork         Create a fork of a repository
	help         CLI help
	id           Manage repository identities
modified crates/radicle-cli/src/commands/debug.rs
@@ -1,7 +1,7 @@
-
#![allow(clippy::or_fun_call)]
+
mod args;
+

use std::collections::BTreeMap;
use std::env;
-
use std::ffi::OsString;
use std::path::PathBuf;
use std::process::Command;

@@ -11,40 +11,16 @@ use serde::Serialize;
use radicle::Profile;

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

+
pub use args::Args;
+
pub(crate) use args::ABOUT;

pub const NAME: &str = "rad";
pub const VERSION: &str = env!("RADICLE_VERSION");
pub const DESCRIPTION: &str = "Radicle command line interface";
pub const GIT_HEAD: &str = env!("GIT_HEAD");

-
pub const HELP: Help = Help {
-
    name: "debug",
-
    description: "Write out information to help debug your Radicle node remotely",
-
    version: env!("RADICLE_VERSION"),
-
    usage: r#"
-
Usage
-

-
    rad debug
-

-
    Run this if you are reporting a problem in Radicle. The output is
-
    helpful for Radicle developers to debug your problem remotely. The
-
    output is meant to not include any sensitive information, but
-
    please check it, and then forward to the Radicle developers.
-

-
"#,
-
};
-

-
#[derive(Debug)]
-
pub struct Options {}
-

-
impl Args for Options {
-
    fn from_args(_args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
-
        Ok((Options {}, vec![]))
-
    }
-
}
-

-
pub fn run(_options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
+
pub fn run(_args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
    match ctx.profile() {
        Ok(profile) => debug(Some(&profile)),
        Err(e) => {
added crates/radicle-cli/src/commands/debug/args.rs
@@ -0,0 +1,13 @@
+
use clap::Parser;
+

+
pub const ABOUT: &str = "Write out information to help debug your Radicle node remotely";
+

+
const LONG_ABOUT: &str = r#"
+
Run this if you are reporting a problem in Radicle. The output is
+
helpful for Radicle developers to debug your problem remotely. The
+
output is meant to not include any sensitive information, but
+
please check it, and then forward to the Radicle developers."#;
+

+
#[derive(Parser, Debug)]
+
#[command(about = ABOUT, long_about = LONG_ABOUT, disable_version_flag = true)]
+
pub struct Args {}
modified crates/radicle-cli/src/commands/help.rs
@@ -42,6 +42,10 @@ const COMMANDS: &[CommandItem] = &[
    CommandItem::Lexopt(crate::commands::checkout::HELP),
    CommandItem::Lexopt(crate::commands::clone::HELP),
    CommandItem::Lexopt(crate::commands::config::HELP),
+
    CommandItem::Clap {
+
        name: "debug",
+
        about: crate::commands::debug::ABOUT,
+
    },
    CommandItem::Lexopt(crate::commands::fork::HELP),
    CommandItem::Lexopt(crate::commands::help::HELP),
    CommandItem::Lexopt(crate::commands::id::HELP),
modified crates/radicle-cli/src/main.rs
@@ -46,6 +46,7 @@ struct CliArgs {
#[derive(Subcommand, Debug)]
enum Commands {
    Clean(clean::Args),
+
    Debug(debug::Args),
    Issue(issue::Args),
    Path(path::Args),
    Stats(stats::Args),
@@ -200,7 +201,9 @@ pub(crate) fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyho
            term::run_command_args::<diff::Options, _>(diff::HELP, diff::run, args.to_vec());
        }
        "debug" => {
-
            term::run_command_args::<debug::Options, _>(debug::HELP, debug::run, args.to_vec());
+
            if let Some(Commands::Debug(args)) = CliArgs::parse().command {
+
                term::run_command_fn(debug::run, args);
+
            }
        }
        "follow" => {
            term::run_command_args::<follow::Options, _>(follow::HELP, follow::run, args.to_vec());