Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Improve missing man page handling
cloudhead committed 2 years ago
commit 9cd1b0ec46c73e42e9c4198909f19a2a748a614f
parent cf8f262cb23282de93d8515af0cef6d49d99f419
3 files changed +21 -4
modified radicle-cli/src/terminal.rs
@@ -79,14 +79,19 @@ where
        Err(err) => {
            let hint = match err.downcast_ref::<Error>() {
                Some(Error::Help) => {
-
                    term::help(help.name, help.version, help.description, help.usage);
+
                    help.print();
                    process::exit(0);
                }
+
                // Print the manual, or the regular help if there's an error.
                Some(Error::HelpManual { name }) => {
                    let Ok(status) = term::manual(name) else {
-
                        io::error(format!("rad {}: failed to load manual page", help.name));
-
                        process::exit(1);
+
                        help.print();
+
                        process::exit(0);
                    };
+
                    if !status.success() {
+
                        help.print();
+
                        process::exit(0);
+
                    }
                    process::exit(status.code().unwrap_or(0));
                }
                Some(Error::Usage) => {
modified radicle-cli/src/terminal/args.rs
@@ -12,6 +12,7 @@ use radicle::node::{Address, Alias};
use radicle::prelude::{Did, NodeId, RepoId};

use crate::git::Rev;
+
use crate::terminal as term;

#[derive(thiserror::Error, Debug)]
pub enum Error {
@@ -39,6 +40,13 @@ pub struct Help {
    pub usage: &'static str,
}

+
impl Help {
+
    /// Print help to stdout.
+
    pub fn print(&self) {
+
        term::help(self.name, self.version, self.description, self.usage);
+
    }
+
}
+

pub trait Args: Sized {
    fn from_env() -> anyhow::Result<Self> {
        let args: Vec<_> = std::env::args_os().skip(1).collect();
modified radicle-term/src/io.rs
@@ -1,5 +1,6 @@
use std::ffi::OsStr;
use std::fmt::Write;
+
use std::process::Stdio;
use std::{env, fmt, io, process};

use inquire::ui::{ErrorMessageRenderConfig, StyleSheet, Styled};
@@ -139,7 +140,10 @@ pub fn help(name: &str, version: &str, description: &str, usage: &str) {
}

pub fn manual(name: &str) -> io::Result<process::ExitStatus> {
-
    let mut child = process::Command::new("man").arg(name).spawn()?;
+
    let mut child = process::Command::new("man")
+
        .arg(name)
+
        .stderr(Stdio::null())
+
        .spawn()?;

    child.wait()
}