cli/path: Use clap
This commit is contained in:
parent
4787b53b1e
commit
753b7aef93
|
|
@ -55,7 +55,10 @@ const COMMANDS: &[CommandItem] = &[
|
|||
CommandItem::Lexopt(crate::commands::ls::HELP),
|
||||
CommandItem::Lexopt(crate::commands::node::HELP),
|
||||
CommandItem::Lexopt(crate::commands::patch::HELP),
|
||||
CommandItem::Lexopt(crate::commands::path::HELP),
|
||||
CommandItem::Clap {
|
||||
name: "path",
|
||||
about: crate::commands::path::ABOUT,
|
||||
},
|
||||
CommandItem::Lexopt(crate::commands::clean::HELP),
|
||||
CommandItem::Lexopt(crate::commands::rad_self::HELP),
|
||||
CommandItem::Lexopt(crate::commands::seed::HELP),
|
||||
|
|
|
|||
|
|
@ -1,54 +1,13 @@
|
|||
#![allow(clippy::or_fun_call)]
|
||||
use std::ffi::OsString;
|
||||
|
||||
use anyhow::anyhow;
|
||||
mod args;
|
||||
|
||||
use radicle::profile;
|
||||
|
||||
use crate::terminal as term;
|
||||
use crate::terminal::args::{Args, Error, Help};
|
||||
|
||||
pub const HELP: Help = Help {
|
||||
name: "path",
|
||||
description: "Display the Radicle home path",
|
||||
version: env!("RADICLE_VERSION"),
|
||||
usage: r#"
|
||||
Usage
|
||||
pub use args::Args;
|
||||
pub(crate) use args::ABOUT;
|
||||
|
||||
rad path [<option>...]
|
||||
|
||||
If no argument is specified, the Radicle home path is displayed.
|
||||
|
||||
Options
|
||||
|
||||
--help Print help
|
||||
|
||||
"#,
|
||||
};
|
||||
|
||||
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());
|
||||
}
|
||||
_ => return Err(anyhow!(arg.unexpected())),
|
||||
}
|
||||
}
|
||||
|
||||
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<()> {
|
||||
let home = profile::home()?;
|
||||
|
||||
println!("{}", home.path().display());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
use clap::Parser;
|
||||
|
||||
pub const ABOUT: &str = "Display the Radicle home path";
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(about = ABOUT, disable_version_flag = true)]
|
||||
pub struct Args {}
|
||||
|
|
@ -46,6 +46,7 @@ struct CliArgs {
|
|||
#[derive(Subcommand, Debug)]
|
||||
enum Commands {
|
||||
Issue(issue::Args),
|
||||
Path(path::Args),
|
||||
Stats(stats::Args),
|
||||
Unseed(unseed::Args),
|
||||
}
|
||||
|
|
@ -239,7 +240,9 @@ pub(crate) fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyho
|
|||
term::run_command_args::<patch::Options, _>(patch::HELP, patch::run, args.to_vec());
|
||||
}
|
||||
"path" => {
|
||||
term::run_command_args::<path::Options, _>(path::HELP, path::run, args.to_vec());
|
||||
if let Some(Commands::Path(args)) = CliArgs::parse().command {
|
||||
term::run_command_fn(path::run, args);
|
||||
}
|
||||
}
|
||||
"publish" => {
|
||||
term::run_command_args::<publish::Options, _>(
|
||||
|
|
|
|||
Loading…
Reference in New Issue