cli/debug: Use clap
This commit is contained in:
parent
2e77d5ef4d
commit
7c89045ea0
|
|
@ -11,6 +11,7 @@ Common `rad` commands used in various situations:
|
||||||
checkout Checkout a repository into the local directory
|
checkout Checkout a repository into the local directory
|
||||||
clone Clone a Radicle repository
|
clone Clone a Radicle repository
|
||||||
config Manage your local Radicle configuration
|
config Manage your local Radicle configuration
|
||||||
|
debug Write out information to help debug your Radicle node remotely
|
||||||
fork Create a fork of a repository
|
fork Create a fork of a repository
|
||||||
help CLI help
|
help CLI help
|
||||||
id Manage repository identities
|
id Manage repository identities
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#![allow(clippy::or_fun_call)]
|
mod args;
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
|
@ -11,40 +11,16 @@ use serde::Serialize;
|
||||||
use radicle::Profile;
|
use radicle::Profile;
|
||||||
|
|
||||||
use crate::terminal as term;
|
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 NAME: &str = "rad";
|
||||||
pub const VERSION: &str = env!("RADICLE_VERSION");
|
pub const VERSION: &str = env!("RADICLE_VERSION");
|
||||||
pub const DESCRIPTION: &str = "Radicle command line interface";
|
pub const DESCRIPTION: &str = "Radicle command line interface";
|
||||||
pub const GIT_HEAD: &str = env!("GIT_HEAD");
|
pub const GIT_HEAD: &str = env!("GIT_HEAD");
|
||||||
|
|
||||||
pub const HELP: Help = Help {
|
pub fn run(_args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
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<()> {
|
|
||||||
match ctx.profile() {
|
match ctx.profile() {
|
||||||
Ok(profile) => debug(Some(&profile)),
|
Ok(profile) => debug(Some(&profile)),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
|
||||||
|
|
@ -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 {}
|
||||||
|
|
@ -45,6 +45,10 @@ const COMMANDS: &[CommandItem] = &[
|
||||||
CommandItem::Lexopt(crate::commands::checkout::HELP),
|
CommandItem::Lexopt(crate::commands::checkout::HELP),
|
||||||
CommandItem::Lexopt(crate::commands::clone::HELP),
|
CommandItem::Lexopt(crate::commands::clone::HELP),
|
||||||
CommandItem::Lexopt(crate::commands::config::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::fork::HELP),
|
||||||
CommandItem::Lexopt(crate::commands::help::HELP),
|
CommandItem::Lexopt(crate::commands::help::HELP),
|
||||||
CommandItem::Lexopt(crate::commands::id::HELP),
|
CommandItem::Lexopt(crate::commands::id::HELP),
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ struct CliArgs {
|
||||||
enum Commands {
|
enum Commands {
|
||||||
Block(block::Args),
|
Block(block::Args),
|
||||||
Clean(clean::Args),
|
Clean(clean::Args),
|
||||||
|
Debug(debug::Args),
|
||||||
Issue(issue::Args),
|
Issue(issue::Args),
|
||||||
Path(path::Args),
|
Path(path::Args),
|
||||||
Stats(stats::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());
|
term::run_command_args::<diff::Options, _>(diff::HELP, diff::run, args.to_vec());
|
||||||
}
|
}
|
||||||
"debug" => {
|
"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" => {
|
"follow" => {
|
||||||
term::run_command_args::<follow::Options, _>(follow::HELP, follow::run, args.to_vec());
|
term::run_command_args::<follow::Options, _>(follow::HELP, follow::run, args.to_vec());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue