Add shell completion and manpage generation (#233)

This commit is contained in:
Marcin Puc
2022-11-26 20:42:35 +01:00
committed by GitHub
parent 37b900c56a
commit f6ec6c76db
5 changed files with 51 additions and 80 deletions

View File

@@ -6,6 +6,7 @@ use std::process::Command;
use std::{env, fs};
use clap::{ArgEnum, Parser};
use clap_complete::Shell;
use color_eyre::eyre;
use color_eyre::eyre::Context;
use color_eyre::eyre::Result;
@@ -489,6 +490,14 @@ pub struct CommandLineArgs {
/// See: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/struct.EnvFilter.html
#[clap(long, default_value = "info")]
pub log_filter: String,
/// Print completion script for the given shell and exit
#[clap(long, arg_enum, hide = true)]
pub gen_completion: Option<Shell>,
/// Print roff manpage and exit
#[clap(long, hide = true)]
pub gen_manpage: bool,
}
impl CommandLineArgs {

View File

@@ -4,6 +4,7 @@ use std::env;
use std::io;
use std::process::exit;
use clap::CommandFactory;
use clap::{crate_version, Parser};
use color_eyre::eyre::Context;
use color_eyre::eyre::{eyre, Result};
@@ -42,6 +43,18 @@ fn run() -> Result<()> {
let opt = CommandLineArgs::parse();
if let Some(shell) = opt.gen_completion {
let cmd = &mut CommandLineArgs::command();
clap_complete::generate(shell, cmd, clap::crate_name!(), &mut std::io::stdout());
return Ok(());
}
if opt.gen_manpage {
let man = clap_mangen::Man::new(CommandLineArgs::command());
man.render(&mut std::io::stdout())?;
return Ok(());
}
install_tracing(&opt.tracing_filter_directives())?;
for env in opt.env_variables() {