From 6705c283aff30b4b982cd130b43428843b98f975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sat, 26 Aug 2023 09:35:02 +0200 Subject: [PATCH] feat: add man page generation --- Cargo.lock | 17 +++++++++++++++++ Cargo.toml | 1 + flake.nix | 3 +++ src/cli.rs | 6 ++++++ src/main.rs | 8 ++++++++ 5 files changed, 35 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 78b6613..1d674b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -343,6 +343,16 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +[[package]] +name = "clap_mangen" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8e5f34d85d9e0bbe2491d100a7a7c1007bb2467b518080bfe311e8947197a9" +dependencies = [ + "clap", + "roff", +] + [[package]] name = "colorchoice" version = "1.0.0" @@ -948,6 +958,12 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +[[package]] +name = "roff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316" + [[package]] name = "rustix" version = "0.37.20" @@ -1165,6 +1181,7 @@ dependencies = [ "anyhow", "clap", "clap_complete_command", + "clap_mangen", "humantime", "libc", "notify-rust", diff --git a/Cargo.toml b/Cargo.toml index 8c2f0e2..9d57901 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" anyhow = "1.0.71" clap = { version = "4.3.4", features = ["derive"] } clap_complete_command = "0.5.1" +clap_mangen = "0.2.13" humantime = "2.1.0" libc = "0.2.147" notify-rust = "4.8.0" diff --git a/flake.nix b/flake.nix index 5be9bfb..c399655 100644 --- a/flake.nix +++ b/flake.nix @@ -17,6 +17,9 @@ nativeBuildInputs = with pkgs; [ installShellFiles ]; meta.mainProgram = "timers"; postInstall = '' + $out/bin/timers manpage timers.1 + installManPage timers.1 + installShellCompletion --cmd timers \ --bash <($out/bin/timers completions bash) \ --fish <($out/bin/timers completions fish) \ diff --git a/src/cli.rs b/src/cli.rs index 08daac2..f71c642 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -61,6 +61,12 @@ pub enum Command { Completions { #[arg(value_enum)] shell: clap_complete_command::Shell, + }, + + /// Generate man page (section 1) + Manpage { + /// File to save the man page to + file_path: String } } diff --git a/src/main.rs b/src/main.rs index 2249f05..7c7d841 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use std::io::Write; mod cli; mod daemon; mod helper; @@ -46,6 +47,13 @@ fn main() -> Result<(), anyhow::Error> { shell.generate(&mut Cli::command(), &mut std::io::stdout()); return Ok(()); } + CliCommand::Manpage { file_path } => { + let man = clap_mangen::Man::new(Cli::command()); + let mut buffer: Vec = Default::default(); + man.render(&mut buffer)?; + std::fs::write(file_path, buffer)?; + return Ok(()); + } }; let answer = send_command(&args.socket, daemon_command)?; print!("{}", answer);