Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Added man page generator #262

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
new: added man page generator
  • Loading branch information
pamburus committed May 16, 2024
commit 57b872c7dc4d7681d6797ededc3c6e4eb1bc82bb
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
1 change: 1 addition & 0 deletions build/ci/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function test() {
${MAIN_EXECUTABLE:?} --config=etc/defaults/config-k8s.yaml > /dev/null
${MAIN_EXECUTABLE:?} --config=etc/defaults/config-ecs.yaml > /dev/null
${MAIN_EXECUTABLE:?} --shell-completions bash > /dev/null
${MAIN_EXECUTABLE:?} --man-page > /dev/null
${MAIN_EXECUTABLE:?} --list-themes > /dev/null
echo "" | ${MAIN_EXECUTABLE:?} --concurrency 4 > /dev/null
}
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 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(());
}

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