Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate man pages #254

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +294 to +296
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion, you can use install instead of cp since install supports setting permissions as part of copying, I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

install doesn't support recursively copying directories so you have to bring in find too, not sure it's worth it.

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
Loading