Skip to content

Commit 393f20b

Browse files
authored
Allow user to generate the man page (#108)
1 parent dcf5563 commit 393f20b

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ xdg = "2.5.2"
1414
bitcode = "0.6.6"
1515
log = "0.4.27"
1616
env_logger = "0.11.8"
17+
clap_mangen = "0.2.28"

flake.nix

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,22 @@
2929
pkgs.callPackage (
3030
{
3131
callPackage,
32-
makeWrapper,
3332
nix,
3433
fzy,
3534
nix-index-unwrapped,
3635
rustPackages,
36+
installShellFiles,
3737
}:
3838
let
3939
naersk-lib = callPackage naersk { };
4040
in
4141
naersk-lib.buildPackage {
4242
pname = "comma";
4343
src = self;
44+
45+
nativeBuildInputs = [
46+
installShellFiles
47+
];
4448
overrideMain = _: {
4549
postPatch = ''
4650
substituteInPlace ./src/main.rs \
@@ -67,6 +71,9 @@
6771
"$out/etc/nushell/comma-command-not-found.nu" \
6872
"$out/etc/fish/functions/comma-command-not-found.fish" \
6973
--replace-fail "comma --ask" "$out/bin/comma --ask"
74+
75+
"$out/bin/comma" --mangen > comma.1
76+
installManPage comma.1
7077
'';
7178
};
7279
checkInputs = [ rustPackages.clippy ];

src/main.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,17 @@ fn main() -> ExitCode {
247247
}
248248
};
249249

250+
if args.mangen {
251+
use clap::CommandFactory;
252+
let man = clap_mangen::Man::new(Opt::command());
253+
254+
if let Err(err) = man.render(&mut std::io::stdout()) {
255+
panic!("{}", err)
256+
} else {
257+
return ExitCode::SUCCESS
258+
}
259+
}
260+
250261
if args.empty_cache {
251262
if let Some(ref mut cache) = cache {
252263
cache.empty();
@@ -373,6 +384,10 @@ fn main() -> ExitCode {
373384
#[derive(Parser)]
374385
#[clap(version = crate_version!(), trailing_var_arg = true)]
375386
struct Opt {
387+
/// Generate the man page, then exit
388+
#[clap(long, hide = true)]
389+
mangen: bool,
390+
376391
/// Install the derivation containing the executable
377392
#[clap(short, long)]
378393
install: bool,
@@ -421,6 +436,6 @@ struct Opt {
421436
delete_entry: bool,
422437

423438
/// Command to run
424-
#[clap(required_unless_present_any = ["empty_cache"], name = "cmd")]
439+
#[clap(required_unless_present_any = ["empty_cache", "mangen"], name = "cmd")]
425440
cmd: Vec<String>,
426441
}

0 commit comments

Comments
 (0)