generate man page and completions

This commit is contained in:
figsoda 2022-12-30 15:36:38 -05:00
parent b3f6b0de79
commit 942b477b0f
6 changed files with 102 additions and 2 deletions

View File

@ -28,6 +28,8 @@ jobs:
run: |
rustup toolchain install stable --profile minimal -t ${{ matrix.target }}
cargo +stable build --target ${{ matrix.target }}
env:
GEN_ARTIFACTS: artifacts
clippy-rustfmt:
name: clippy-rustfmt

View File

@ -53,3 +53,32 @@ jobs:
tag: ${{ github.ref }}
file: target/${{ matrix.target }}/release/nurl${{ matrix.ext }}
asset_name: nurl-${{ matrix.target }}${{ matrix.ext }}
artifacts:
name: artifacts
needs: create_release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cargo build
run: |
rustup toolchain install nightly --profile minimal
cargo +nightly build
env:
GEN_ARTIFACTS: artifacts
- name: Rename generated artifacts
run: |
mv artifacts/{_,}nurl.ps1
mv artifacts/{_nurl,nurl.zsh}
- name: Upload artifacts
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ github.token }}
tag: ${{ github.ref }}
file: artifacts/*
file_glob: true

27
Cargo.lock generated
View File

@ -38,6 +38,15 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "clap_complete"
version = "4.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10861370d2ba66b0f5989f83ebf35db6421713fd92351790e7fdd6c36774c56b"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "4.0.21"
@ -60,6 +69,16 @@ dependencies = [
"os_str_bytes",
]
[[package]]
name = "clap_mangen"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904eb24d05ad587557e0f484ddce5c737c30cf81372badb16d13e41c4b8340b1"
dependencies = [
"clap",
"roff",
]
[[package]]
name = "enum_dispatch"
version = "0.3.9"
@ -179,6 +198,8 @@ version = "0.1.1"
dependencies = [
"anyhow",
"clap",
"clap_complete",
"clap_mangen",
"enum_dispatch",
"indoc",
"serde",
@ -246,6 +267,12 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "roff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
[[package]]
name = "rustix"
version = "0.36.6"

View File

@ -23,6 +23,12 @@ url = "2.3.1"
version = "4.0.32"
features = ["cargo", "derive", "unicode", "wrap_help"]
[build-dependencies]
clap = { version = "4.0.32", features = ["derive"] }
clap_complete = "4.0.7"
clap_mangen = "0.2.6"
url = "2.3.1"
[profile.release]
lto = true
panic = "abort"

29
build.rs Normal file
View File

@ -0,0 +1,29 @@
use clap::CommandFactory;
use clap_complete::{generate_to, Shell};
use clap_mangen::Man;
use std::{
env,
fs::{create_dir_all, File},
path::Path,
};
include!("src/cli.rs");
fn main() {
println!("cargo:rerun-if-env-changed=GEN_ARTIFACTS");
if let Some(dir) = env::var_os("GEN_ARTIFACTS") {
let out = &Path::new(&dir);
create_dir_all(out).unwrap();
let cmd = &mut Opts::command();
Man::new(cmd.clone())
.render(&mut File::create(out.join("nurl.1")).unwrap())
.unwrap();
for shell in Shell::value_variants() {
generate_to(*shell, cmd, "nurl", out).unwrap();
}
}
}

View File

@ -23,7 +23,7 @@
packages = forEachSystem (system:
let
inherit (nixpkgs.legacyPackages.${system})
gitMinimal makeWrapper mercurial nix rustPlatform;
gitMinimal installShellFiles makeWrapper mercurial nix rustPlatform;
in
{
default = rustPlatform.buildRustPackage {
@ -34,13 +34,20 @@
cargoLock.lockFile = self + "/Cargo.lock";
nativeBuildInputs = [ makeWrapper ];
nativeBuildInputs = [
installShellFiles
makeWrapper
];
postInstall = ''
wrapProgram $out/bin/nurl \
--prefix PATH : ${makeBinPath [ gitMinimal mercurial nix ]}
installManPage artifacts/nurl.1
installShellCompletion artifacts/nurl.{bash,fish} --zsh artifacts/_nurl
'';
GEN_ARTIFACTS = "artifacts";
meta = {
inherit (package) description;
license = licenses.mpl20;