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::ls::HELP),
|
||||||
CommandItem::Lexopt(crate::commands::node::HELP),
|
CommandItem::Lexopt(crate::commands::node::HELP),
|
||||||
CommandItem::Lexopt(crate::commands::patch::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::clean::HELP),
|
||||||
CommandItem::Lexopt(crate::commands::rad_self::HELP),
|
CommandItem::Lexopt(crate::commands::rad_self::HELP),
|
||||||
CommandItem::Lexopt(crate::commands::seed::HELP),
|
CommandItem::Lexopt(crate::commands::seed::HELP),
|
||||||
|
|
|
||||||
|
|
@ -1,54 +1,13 @@
|
||||||
#![allow(clippy::or_fun_call)]
|
mod args;
|
||||||
use std::ffi::OsString;
|
|
||||||
|
|
||||||
use anyhow::anyhow;
|
|
||||||
|
|
||||||
use radicle::profile;
|
use radicle::profile;
|
||||||
|
|
||||||
use crate::terminal as term;
|
use crate::terminal as term;
|
||||||
use crate::terminal::args::{Args, Error, Help};
|
|
||||||
|
|
||||||
pub const HELP: Help = Help {
|
pub use args::Args;
|
||||||
name: "path",
|
pub(crate) use args::ABOUT;
|
||||||
description: "Display the Radicle home path",
|
|
||||||
version: env!("RADICLE_VERSION"),
|
|
||||||
usage: r#"
|
|
||||||
Usage
|
|
||||||
|
|
||||||
rad path [<option>...]
|
pub fn run(_args: Args, _ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
|
|
||||||
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<()> {
|
|
||||||
let home = profile::home()?;
|
let home = profile::home()?;
|
||||||
|
|
||||||
println!("{}", home.path().display());
|
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)]
|
#[derive(Subcommand, Debug)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
Issue(issue::Args),
|
Issue(issue::Args),
|
||||||
|
Path(path::Args),
|
||||||
Stats(stats::Args),
|
Stats(stats::Args),
|
||||||
Unseed(unseed::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());
|
term::run_command_args::<patch::Options, _>(patch::HELP, patch::run, args.to_vec());
|
||||||
}
|
}
|
||||||
"path" => {
|
"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" => {
|
"publish" => {
|
||||||
term::run_command_args::<publish::Options, _>(
|
term::run_command_args::<publish::Options, _>(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue