Compare commits

...

1 Commits

Author SHA1 Message Date
Moritz Böhme 6705c283af
feat: add man page generation 2023-08-26 09:35:02 +02:00
5 changed files with 35 additions and 0 deletions

17
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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) \

View File

@ -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
}
}

View File

@ -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<u8> = Default::default();
man.render(&mut buffer)?;
std::fs::write(file_path, buffer)?;
return Ok(());
}
};
let answer = send_command(&args.socket, daemon_command)?;
print!("{}", answer);