diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 94ce69e..10daf0e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,6 +37,10 @@ jobs: profile: minimal toolchain: stable target: x86_64-unknown-linux-gnu + - run: | + mkdir -p target/man + cargo run --features gen-man-pages -- target/man + gzip -9 target/man/*.1 - uses: taiki-e/install-action@v2 with: tool: cargo-deb diff --git a/Cargo.lock b/Cargo.lock index 4b7a363..280555d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -200,6 +200,16 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" +[[package]] +name = "clap_mangen" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbae9cbfdc5d4fa8711c09bd7b83f644cb48281ac35bf97af3e47b0675864bdf" +dependencies = [ + "clap", + "roff", +] + [[package]] name = "colorchoice" version = "1.0.3" @@ -514,6 +524,12 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "roff" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88f8660c1ff60292143c98d08fc6e2f654d722db50410e3f3797d40baaf9d8f3" + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -567,6 +583,7 @@ dependencies = [ "assert_cmd", "bincode", "clap", + "clap_mangen", "fastrand", "function_name", "itertools", diff --git a/Cargo.toml b/Cargo.toml index 5a4a235..0d4576a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ strip = true anyhow = { version = "1.0.93", default-features = false, features = ["std", "backtrace"] } bincode = { version = "1.3.3", default-features = false } clap = { version = "4.5.21", default-features = false, features = ["std", "color", "help", "usage", "error-context", "suggestions", "derive"] } +clap_mangen = { version = "0.2.24", default-features = false, optional = true } function_name = { version = "0.3.0", default-features = false } itertools = { version = "0.13.0", default-features = false, features = ["use_std"] } log = { version = "0.4.22", default-features = false, features = ["max_level_trace", "release_max_level_info"] } @@ -39,6 +40,7 @@ pretty_assertions = { version = "1.4.1", default-features = false, features = [" [features] default = [] as-root = [] # for tests only +gen-man-pages = ["dep:clap_mangen"] nightly = [] # for benchmarks only [lints.rust] @@ -102,3 +104,7 @@ verbose_file_reads = "warn" [package.metadata.deb] name = "shh" depends = "$auto, strace" +assets = [ + ["target/release/shh", "usr/bin/", "755"], + ["target/man/*.1.gz", "usr/share/man/man1/", "644"] +] diff --git a/src/main.rs b/src/main.rs index 4184ef7..5d2204b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,10 @@ //! Systemd Hardening Helper #![cfg_attr(all(feature = "nightly", test), feature(test))] +#![cfg_attr( + feature = "gen-man-pages", + expect(dead_code, unused_crate_dependencies, unused_imports) +)] use std::{ fs::{self, File}, @@ -32,6 +36,18 @@ fn sd_options( sd_opts } +#[cfg(feature = "gen-man-pages")] +fn main() -> anyhow::Result<()> { + use clap::CommandFactory as _; + let cmd = cl::Args::command(); + let output = std::env::args_os() + .nth(1) + .ok_or_else(|| anyhow::anyhow!("Missing output dir argument"))?; + clap_mangen::generate_to(cmd, output)?; + Ok(()) +} + +#[cfg(not(feature = "gen-man-pages"))] fn main() -> anyhow::Result<()> { // Init logger simple_logger::SimpleLogger::new()