diff --git a/radicle-cli/src/commands.rs b/radicle-cli/src/commands.rs index b03d90d5..bdeb5d52 100644 --- a/radicle-cli/src/commands.rs +++ b/radicle-cli/src/commands.rs @@ -20,6 +20,8 @@ pub mod rad_ls; pub mod rad_merge; #[path = "commands/patch.rs"] pub mod rad_patch; +#[path = "commands/path.rs"] +pub mod rad_path; #[path = "commands/push.rs"] pub mod rad_push; #[path = "commands/review.rs"] diff --git a/radicle-cli/src/commands/path.rs b/radicle-cli/src/commands/path.rs new file mode 100644 index 00000000..121db814 --- /dev/null +++ b/radicle-cli/src/commands/path.rs @@ -0,0 +1,56 @@ +#![allow(clippy::or_fun_call)] +use std::ffi::OsString; + +use anyhow::anyhow; +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!("CARGO_PKG_VERSION"), + usage: r#" +Usage + + rad path [--help] + + 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) -> anyhow::Result<(Self, Vec)> { + 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") => { + 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()?; + + println!("{}", home.display()); + + Ok(()) +} diff --git a/radicle-cli/src/main.rs b/radicle-cli/src/main.rs index 296f175d..d72748cd 100644 --- a/radicle-cli/src/main.rs +++ b/radicle-cli/src/main.rs @@ -198,6 +198,14 @@ fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option> args.to_vec(), ); } + "path" => { + term::run_command_args::( + rad_path::HELP, + "Command", + rad_path::run, + args.to_vec(), + ); + } _ => { let exe = format!("{}-{}", NAME, exe); let status = process::Command::new(exe.clone()).args(args).status();