wasmer_cli/commands/
gen_manpage.rs

1use super::WasmerCmd;
2use anyhow::Context;
3use clap::CommandFactory;
4use clap_mangen::generate_to;
5use std::path::PathBuf;
6use std::sync::LazyLock;
7
8static DEFAULT_MAN_DIR_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
9    dirs::data_dir()
10        .unwrap_or_default()
11        .join("man")
12        .join("man1")
13});
14
15#[derive(Debug, Clone, clap::Parser)]
16pub struct CmdGenManPage {
17    /// Where to store the generated file(s) to.
18    #[clap(long, default_value = DEFAULT_MAN_DIR_PATH.as_os_str())]
19    pub out: PathBuf,
20}
21
22impl CmdGenManPage {
23    pub fn execute(&self) -> anyhow::Result<()> {
24        let cmd = WasmerCmd::command();
25        generate_to(cmd, &self.out).context(format!(
26            "While generating the man page(s) to {}",
27            self.out.display()
28        ))
29    }
30}