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

optparse-bash: Init at 2021-06-13 #121937

Merged
merged 1 commit into from
Aug 11, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 63 additions & 0 deletions pkgs/development/libraries/optparse-bash/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;

checkInputs = [ bash ];

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

installPhase = ''
runHook preInstall
mkdir -p $out/bin
mv optparse.bash $out/bin/
Copy link
Contributor

Choose a reason for hiding this comment

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

./results/optparse-bash/bin/optparse.bash
bash: ./results/optparse-bash/bin/optparse.bash: Permission denied

You can use 'install' command to set permission.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@superherointj

optparse.bash is meant to be sourced (as a "header file" of BASH functions) instead of being executed.

I put it inside $out/bin so that users can source it like

source optparse.bash

instead of

source /nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-optparse-bash-0000-00-00/libexec/optparse.bash

Is there a cleaner approach of doing so?

Copy link
Member

Choose a reason for hiding this comment

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

If you use it in a nix package then you can substitute the store path with ${optparse}/libexec/optparse.bash.

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 ];
};
}
2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17798,6 +17798,8 @@ in

openrct2 = callPackage ../games/openrct2 { };

optparse-bash = callPackage ../development/libraries/optparse-bash { };

orcania = callPackage ../development/libraries/orcania { };

osm-gps-map = callPackage ../development/libraries/osm-gps-map { };
Expand Down