Skip to content

Commit

Permalink
Generate man pages
Browse files Browse the repository at this point in the history
  • Loading branch information
9999years committed May 22, 2024
1 parent 26a5dde commit 1a8113c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ camino = "1.1.4"
# Clap 4.4 is the last version supporting Rust 1.72.
clap = { version = "~4.4", features = ["derive", "wrap_help", "env", "string"] }
clap_complete = "~4.4"
clap_mangen = { version = "=0.2.19", optional = true }
clearscreen = "2.0.1"
command-group = { version = "2.1.0", features = ["tokio", "with-tokio"] }
crossterm = { version = "0.27.0", features = ["event-stream"] }
Expand Down
37 changes: 36 additions & 1 deletion nix/packages/ghciwatch.nix
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,31 @@
};
};

ghciwatch-man = craneLib.buildPackage (releaseArgs
// {
pnameSuffix = "-man";

cargoExtraArgs = "--locked --features clap_mangen";

nativeBuildInputs = (releaseArgs.nativeBuildInputs or []) ++ [installShellFiles];

postInstall =
(releaseArgs.postInstall or "")
+ lib.optionalString can-run-ghciwatch ''
manpages=$(mktemp -d)
${run-ghciwatch} --generate-man-pages "$manpages"
for manpage in "$manpages"/*; do
installManPage "$manpage"
done
rm -rf "$out/bin"
'';
});

ghciwatch-with-clap-markdown = craneLib.buildPackage (releaseArgs
// {
pnameSuffix = "-cli-markdown";

cargoExtraArgs = "--locked --features clap-markdown";
});

Expand Down Expand Up @@ -261,4 +284,16 @@
];
};
in
craneLib.buildPackage releaseArgs
craneLib.buildPackage (releaseArgs
// {
postInstall =
(releaseArgs.postInstall or "")
+ ''
cp -r ${ghciwatch-man}/share $out/share
# For some reason this is needed to strip references:
# stripping references to cargoVendorDir from share/man/man1/ghciwatch.1.gz
# sed: couldn't open temporary file share/man/man1/sedwVs75O: Permission denied
chmod -R +w $out/share
'';
})
5 changes: 5 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ pub struct Opts {
#[arg(long, hide = true)]
pub generate_markdown_help: bool,

/// Generate `man` pages in the given directory.
#[cfg(feature = "clap_mangen")]
#[arg(long, hide = true)]
pub generate_man_pages: Option<Utf8PathBuf>,

/// Generate shell completions for the given shell.
#[arg(long)]
pub completions: Option<Shell>,
Expand Down
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ async fn main() -> miette::Result<()> {
return Ok(());
}

#[cfg(feature = "clap_mangen")]
if let Some(out_dir) = opts.generate_man_pages {
use miette::IntoDiagnostic;
use miette::WrapErr;

let command = cli::Opts::command();
clap_mangen::generate_to(command, out_dir)
.into_diagnostic()
.wrap_err("Failed to generate man pages")?;
return Ok(());
}

if let Some(shell) = opts.completions {
let mut command = cli::Opts::command();
clap_complete::generate(shell, &mut command, "ghciwatch", &mut std::io::stdout());
Expand Down

0 comments on commit 1a8113c

Please sign in to comment.