Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add `rad-path` command
Alexis Sellier committed 3 years ago
commit bdeebfb79ab230127191a0276d8f1573a8d54fd7
parent 26fa16d2b2988117c06fcf184f4d86d4fd8fec53
3 files changed +66 -0
modified 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"]
added 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<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") => {
+
                    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(())
+
}
modified radicle-cli/src/main.rs
@@ -198,6 +198,14 @@ fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyhow::Error>>
                args.to_vec(),
            );
        }
+
        "path" => {
+
            term::run_command_args::<rad_path::Options, _>(
+
                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();