cli/debug: Use clap

This commit is contained in:
Lorenz Leutgeb 2025-10-01 22:35:49 +02:00 committed by Erik Kundt
parent 2e77d5ef4d
commit 7c89045ea0
5 changed files with 28 additions and 31 deletions

View File

@ -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

View File

@ -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) => {

View File

@ -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 {}

View File

@ -45,6 +45,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),

View File

@ -47,6 +47,7 @@ struct CliArgs {
enum Commands {
Block(block::Args),
Clean(clean::Args),
Debug(debug::Args),
Issue(issue::Args),
Path(path::Args),
Stats(stats::Args),
@ -203,7 +204,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());