Skip to content

Commit

Permalink
new: added man page generator
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed May 16, 2024
1 parent c42cc35 commit 5a0e313
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
21 changes: 19 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = [".", "crate/encstr"]
[workspace.package]
repository = "https://github.com/pamburus/hl"
authors = ["Pavel Ivanov <mr.pavel.ivanov@gmail.com>"]
version = "0.29.5-alpha.1"
version = "0.29.5-alpha.2"
edition = "2021"
license = "MIT"

Expand Down Expand Up @@ -41,6 +41,7 @@ chrono = { version = "0.4", default-features = false, features = [
chrono-tz = { version = "0", features = ["serde"] }
clap = { version = "4", features = ["wrap_help", "derive", "env", "string"] }
clap_complete = "4"
clap_mangen = "0"
closure = "0"
collection_macros = "0"
config = "0"
Expand Down
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ build-release: contrib-build
@cargo build --release --locked
.PHONY: build-release

## Install binary
install: contrib-build
## Install binary and man pages
install: contrib-build install-man-pages
@cargo install --path . --locked
.PHONY: install

## Install man pages
install-man-pages: ~/share/man/man1/hl.1
@echo $$(tput setaf 3)NOTE:$$(tput sgr0) ensure $$(tput setaf 2)~/share/man$$(tput sgr0) is added to $$(tput setaf 2)MANPATH$$(tput sgr0) environment variable
.PHONY: install-man-pages

~/share/man/man1/hl.1: contrib-build | ~/share/man/man1
@HL_CONFIG= cargo run --release --locked -- --man-page >$@

~/share/man/man1:
@mkdir -p $@

## Install versioned binary
install-versioned: contrib-build
@cargo install --path . --locked
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ Advanced Options:
--max-message-size <SIZE> Maximum message size [env: HL_MAX_MESSAGE_SIZE=] [default: "64 MiB"]
-C, --concurrency <N> Number of processing threads [env: HL_CONCURRENCY=]
--shell-completions <SHELL> Print shell auto-completion script and exit [possible values: bash, elvish, fish, powershell, zsh]
--man-page Print man page and exit
--list-themes Print available themes and exit
--dump-index Print debug index metadata (in --sort mode) and exit
--debug Print debug error messages that can help with troubleshooting
Expand Down
11 changes: 10 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,18 @@ pub struct Opt {
pub concurrency: Option<usize>,

/// Print shell auto-completion script and exit.
#[arg(long, value_parser = value_parser!(Shell), value_name = "SHELL", help_heading = heading::ADVANCED)]
#[arg(
long,
value_parser = value_parser!(Shell),
value_name = "SHELL",
help_heading = heading::ADVANCED,
)]
pub shell_completions: Option<Shell>,

/// Print man page and exit.
#[arg(long, help_heading = heading::ADVANCED)]
pub man_page: bool,

Check warning on line 398 in src/cli.rs

View check run for this annotation

Codecov / codecov/patch

src/cli.rs#L398

Added line #L398 was not covered by tests

/// Print available themes and exit.
#[arg(long, help_heading = heading::ADVANCED)]
pub list_themes: bool,
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ fn run() -> Result<()> {
return Ok(());
}

if opt.man_page {
let man = clap_mangen::Man::new(cli::Opt::command());
man.render(&mut stdout())?;
return Ok(());

Check warning on line 52 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L50-L52

Added lines #L50 - L52 were not covered by tests
}

let color_supported = if stdout().is_terminal() {
if let Err(err) = hl::enable_ansi_support() {
eprintln!("failed to enable ansi support: {}", err);
Expand Down

0 comments on commit 5a0e313

Please sign in to comment.