radicle_cli/commands/
path.rs

1#![allow(clippy::or_fun_call)]
2use std::ffi::OsString;
3
4use anyhow::anyhow;
5
6use radicle::profile;
7
8use crate::terminal as term;
9use crate::terminal::args::{Args, Error, Help};
10
11pub const HELP: Help = Help {
12    name: "path",
13    description: "Display the Radicle home path",
14    version: env!("RADICLE_VERSION"),
15    usage: r#"
16Usage
17
18    rad path [<option>...]
19
20    If no argument is specified, the Radicle home path is displayed.
21
22Options
23
24    --help    Print help
25
26"#,
27};
28
29pub struct Options {}
30
31impl Args for Options {
32    fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
33        use lexopt::prelude::*;
34
35        let mut parser = lexopt::Parser::from_args(args);
36
37        #[allow(clippy::never_loop)]
38        while let Some(arg) = parser.next()? {
39            match arg {
40                Long("help") | Short('h') => {
41                    return Err(Error::Help.into());
42                }
43                _ => return Err(anyhow!(arg.unexpected())),
44            }
45        }
46
47        Ok((Options {}, vec![]))
48    }
49}
50
51pub fn run(_options: Options, _ctx: impl term::Context) -> anyhow::Result<()> {
52    let home = profile::home()?;
53
54    println!("{}", home.path().display());
55
56    Ok(())
57}