1{
2 lib,
3 stdenv,
4 rustPlatform,
5 fetchFromGitHub,
6 installShellFiles,
7 nix-update-script,
8 usage,
9 testers,
10}:
11
12rustPlatform.buildRustPackage (finalAttrs: {
13 pname = "usage";
14 version = "2.1.1";
15
16 src = fetchFromGitHub {
17 owner = "jdx";
18 repo = "usage";
19 tag = "v${finalAttrs.version}";
20 hash = "sha256-aMO/3geF1iFnMi0ZqBdnikp/Qh25vqpeaxdTiQtt5yI=";
21 };
22
23 cargoHash = "sha256-0NQZtT3xz4MaqY8ehKzy/cpDJlE5eWIixi3IropK11w=";
24
25 postPatch = ''
26 substituteInPlace ./examples/mounted.sh \
27 --replace-fail '/usr/bin/env -S usage' "$(pwd)/target/${stdenv.targetPlatform.rust.rustcTargetSpec}/release/usage"
28 '';
29
30 nativeBuildInputs = [ installShellFiles ];
31
32 postInstall = ''
33 installShellCompletion --cmd usage \
34 --bash <($out/bin/usage --completions bash) \
35 --fish <($out/bin/usage --completions fish) \
36 --zsh <($out/bin/usage --completions zsh)
37 '';
38
39 passthru = {
40 updateScript = nix-update-script { };
41 tests.version = testers.testVersion { package = usage; };
42 };
43
44 meta = {
45 homepage = "https://usage.jdx.dev";
46 description = "Specification for CLIs";
47 changelog = "https://github.com/jdx/usage/releases/tag/v${finalAttrs.version}";
48 license = lib.licenses.mit;
49 maintainers = with lib.maintainers; [ konradmalik ];
50 mainProgram = "usage";
51 };
52})