cli: Improve missing man page handling
Instead of saying "no manual entry", we output regular help.
This commit is contained in:
parent
cf8f262cb2
commit
9cd1b0ec46
|
|
@ -79,14 +79,19 @@ where
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let hint = match err.downcast_ref::<Error>() {
|
let hint = match err.downcast_ref::<Error>() {
|
||||||
Some(Error::Help) => {
|
Some(Error::Help) => {
|
||||||
term::help(help.name, help.version, help.description, help.usage);
|
help.print();
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
|
// Print the manual, or the regular help if there's an error.
|
||||||
Some(Error::HelpManual { name }) => {
|
Some(Error::HelpManual { name }) => {
|
||||||
let Ok(status) = term::manual(name) else {
|
let Ok(status) = term::manual(name) else {
|
||||||
io::error(format!("rad {}: failed to load manual page", help.name));
|
help.print();
|
||||||
process::exit(1);
|
process::exit(0);
|
||||||
};
|
};
|
||||||
|
if !status.success() {
|
||||||
|
help.print();
|
||||||
|
process::exit(0);
|
||||||
|
}
|
||||||
process::exit(status.code().unwrap_or(0));
|
process::exit(status.code().unwrap_or(0));
|
||||||
}
|
}
|
||||||
Some(Error::Usage) => {
|
Some(Error::Usage) => {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ use radicle::node::{Address, Alias};
|
||||||
use radicle::prelude::{Did, NodeId, RepoId};
|
use radicle::prelude::{Did, NodeId, RepoId};
|
||||||
|
|
||||||
use crate::git::Rev;
|
use crate::git::Rev;
|
||||||
|
use crate::terminal as term;
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
|
@ -39,6 +40,13 @@ pub struct Help {
|
||||||
pub usage: &'static str,
|
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 {
|
pub trait Args: Sized {
|
||||||
fn from_env() -> anyhow::Result<Self> {
|
fn from_env() -> anyhow::Result<Self> {
|
||||||
let args: Vec<_> = std::env::args_os().skip(1).collect();
|
let args: Vec<_> = std::env::args_os().skip(1).collect();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
use std::process::Stdio;
|
||||||
use std::{env, fmt, io, process};
|
use std::{env, fmt, io, process};
|
||||||
|
|
||||||
use inquire::ui::{ErrorMessageRenderConfig, StyleSheet, Styled};
|
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> {
|
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()
|
child.wait()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue