Skip to content

Commit

Permalink
Add manpage and completions output
Browse files Browse the repository at this point in the history
  • Loading branch information
svenstaro committed Oct 10, 2022
1 parent ef42c50 commit 1c012f1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- next-header -->

## [Unreleased] - ReleaseDate
- Add manpage printing via `--print-manpage`
- Add completions printing via `--print-completions`

## [1.2.1] - 2022-10-10
- Enable multiple parallel decryptions to run in bruteforce [#414](https://github.com/svenstaro/genact/pull/414) (thanks @equal-l2)
Expand Down
27 changes: 27 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ sha2 = "0.10.6"
yansi = "0.5"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
clap = { version = "4.0", features = ["derive", "wrap_help"] }
clap = { version = "4.0", features = ["derive", "cargo", "wrap_help"] }
clap_complete = "4"
clap_mangen = "0.2"
ctrlc = { version = "3.2", features = ["termination"] }
terminal_size = "0.2"

Expand Down
8 changes: 8 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ pub struct AppConfig {
/// Exit after running this many modules
#[clap(long, value_parser = parse_min_1)]
pub exit_after_modules: Option<u32>,

/// Generate completion file for a shell
#[clap(long = "print-completions", value_name = "shell")]
pub print_completions: Option<clap_complete::Shell>,

/// Generate man page
#[clap(long = "print-manpage")]
pub print_manpage: bool,
}

#[cfg(target_arch = "wasm32")]
Expand Down
18 changes: 18 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,27 @@ use genact::exit_handler;
#[cfg(not(target_arch = "wasm32"))]
#[async_std::main]
async fn main() -> Result<()> {
use clap::CommandFactory;
use genact::args::AppConfig;

yansi::Paint::enable_windows_ascii();

let appconfig = parse_args();

if let Some(shell) = appconfig.print_completions {
let mut clap_app = AppConfig::command();
let app_name = clap_app.get_name().to_string();
clap_complete::generate(shell, &mut clap_app, app_name, &mut std::io::stdout());
return Ok(());
}

if appconfig.print_manpage {
let clap_app = AppConfig::command();
let man = clap_mangen::Man::new(clap_app);
man.render(&mut std::io::stdout())?;
return Ok(());
}

*SPEED_FACTOR.lock().await = appconfig.speed_factor;

if appconfig.list_modules_and_exit {
Expand Down

0 comments on commit 1c012f1

Please sign in to comment.