-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mangen and completions binaries
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,26 @@ | ||
use clap::{CommandFactory, ValueEnum}; | ||
use clap_complete::Shell; | ||
use flawz::args::Args; | ||
use std::env; | ||
use std::io::Result; | ||
|
||
/// Environment variable for the output directory. | ||
const OUT_DIR_ENV: &str = "OUT_DIR"; | ||
|
||
/// Shell completions can be created with: | ||
/// | ||
/// ```sh | ||
/// cargo run --bin flawz-completions | ||
/// ``` | ||
/// | ||
/// in a directory specified by the environment variable OUT_DIR. | ||
/// See <https://doc.rust-lang.org/cargo/reference/environment-variables.html> | ||
fn main() -> Result<()> { | ||
let out_dir = env::var(OUT_DIR_ENV).unwrap_or_else(|_| panic!("{OUT_DIR_ENV} is not set")); | ||
let mut app = Args::command(); | ||
for &shell in Shell::value_variants() { | ||
clap_complete::generate_to(shell, &mut app, env!("CARGO_PKG_NAME"), &out_dir)?; | ||
} | ||
println!("Completion scripts are generated in {out_dir:?}"); | ||
Ok(()) | ||
} |
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,30 @@ | ||
use clap::CommandFactory; | ||
use clap_mangen::Man; | ||
use flawz::args::Args; | ||
use std::env; | ||
use std::fs; | ||
use std::io::Result; | ||
use std::path::PathBuf; | ||
|
||
/// Environment variable for the output directory. | ||
const OUT_DIR_ENV: &str = "OUT_DIR"; | ||
|
||
/// Man page can be created with: | ||
/// | ||
/// ```sh | ||
/// cargo run --bin flawz-mangen | ||
/// ```` | ||
/// | ||
/// in a directory specified by the environment variable OUT_DIR. | ||
/// See <https://doc.rust-lang.org/cargo/reference/environment-variables.html> | ||
fn main() -> Result<()> { | ||
let out_dir = env::var(OUT_DIR_ENV).unwrap_or_else(|_| panic!("{OUT_DIR_ENV} is not set")); | ||
let out_path = PathBuf::from(out_dir).join(format!("{}.1", env!("CARGO_PKG_NAME"))); | ||
let app = Args::command(); | ||
let man = Man::new(app); | ||
let mut buffer = Vec::<u8>::new(); | ||
man.render(&mut buffer)?; | ||
fs::write(&out_path, buffer)?; | ||
println!("Man page is generated at {out_path:?}"); | ||
Ok(()) | ||
} |