diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45cb8bb..4490b5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3247939..7372ce1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/Cargo.lock b/Cargo.lock index 8a9c5f2..3f63f75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index b6fd046..728aeb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..15ff911 --- /dev/null +++ b/build.rs @@ -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(); + } + } +} diff --git a/flake.nix b/flake.nix index b4e26cd..a821b72 100644 --- a/flake.nix +++ b/flake.nix @@ -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;