-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reorganize manpages generation
- Loading branch information
1 parent
8a12065
commit 1509583
Showing
3 changed files
with
42 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::io::Result as IoResult; | ||
use std::path::Path; | ||
|
||
use clap::{Command, CommandFactory}; | ||
use clap_mangen::Man; | ||
|
||
use crate::Cli; | ||
|
||
pub fn generate_manpages(out_dir: &Path) -> IoResult<()> { | ||
std::fs::create_dir_all(out_dir)?; | ||
|
||
let cog = Cli::command(); | ||
|
||
for mut subcmd in cog.get_subcommands().filter(|c| !c.is_hide_set()).cloned() { | ||
let name = subcmd.get_name(); | ||
let full_name = format!("cog-{}", name); | ||
let man_name = format!("{}.1", full_name); | ||
|
||
subcmd = subcmd.name(&full_name); | ||
|
||
render_command(&out_dir.join(&man_name), subcmd)?; | ||
} | ||
|
||
render_command(&out_dir.join("cog.1"), cog)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn render_command(file: &Path, cmd: Command) -> IoResult<()> { | ||
let man = Man::new(cmd); | ||
let mut buffer = Vec::new(); | ||
|
||
man.render(&mut buffer)?; | ||
std::fs::write(file, buffer)?; | ||
|
||
Ok(()) | ||
} |