about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/optparse-bash/default.nix
blob: f14512c5272ac8eff9fa9e371292ca39fa980131 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{ stdenvNoCC
, lib
, fetchFromGitHub
, bash
, gnused
, gawk
, coreutils
}:

stdenvNoCC.mkDerivation {
  pname = "optparse-bash-unstable";
  version = "2021-06-13";

  src = fetchFromGitHub {
    owner = "nk412";
    repo = "optparse";
    rev = "d86ec17d15368e5b54eb2d47b001b0b61d68bbd0";
    sha256 = "sha256-vs7Jo1+sV0tPse4Wu2xtzSX1IkahwLgO3e4Riz3uMmI=";
  };

  postPatch = ''
    substituteInPlace optparse.bash \
      --replace sed "${gnused}/bin/sed" \
      --replace awk "${gawk}/bin/awk" \
      --replace printf "${coreutils}/bin/printf"
'';

  dontBuild = true;

  doCheck = true;

  nativeCheckInputs = [ bash ];

  # `#!/usr/bin/env` isn't okay for OfBorg
  # Need external bash to run
  checkPhase = ''
    runHook preCheck
    bash ./sample_head.sh -v --file README.md
    runHook postCheck
  '';

  installPhase = ''
    runHook preInstall
    mkdir -p $out/bin
    mv optparse.bash $out/bin/
    mkdir -p $out/share/doc/optparse-bash
    mv README.md sample_head.sh $out/share/doc/optparse-bash/
    runHook postInstall
  '';

  # As example code,
  # sample_head.sh shows how users can use opt-parse in their script,
  # and its shebang (`/usr/bin/env bash`) should not be patched.
  dontPatchShebangs = true;

  meta = with lib; {
    description = "A BASH wrapper for getopts, for simple command-line argument parsing";
    homepage = "https://github.com/nk412/optparse";
    license = licenses.mit;
    platforms = platforms.all;
    maintainers = with maintainers; [ ShamrockLee ];
  };
}