Add `rad-path` command
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
26fa16d2b2
commit
bdeebfb79a
|
|
@ -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"]
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue