Skip to content

Commit

Permalink
feat(tools): introduce writeShellApplicationWithArgs
Browse files Browse the repository at this point in the history
Signed-off-by: aeryz <[email protected]>
  • Loading branch information
aeryz committed Nov 2, 2023
1 parent c005f64 commit 14e231b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@
args = {
inherit nixpkgs dbg get-flake;

writeShellApplicationWithArgs = import ./tools/writeShellApplicationWithArgs.nix { inherit pkgs; };

pkgs = nixpkgs.legacyPackages.${system}.appendOverlays
(with inputs; [
rust-overlay.overlays.default
Expand Down
19 changes: 19 additions & 0 deletions tools/writeShellApplicationWithArgs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ pkgs }:
{ name, runtimeInputs ? [ ], arguments, text }: pkgs.writeShellApplication {
inherit name;
runtimeInputs = [ pkgs.argc ] ++ runtimeInputs;
text = ''
${builtins.concatStringsSep "\n" (map (arg: "# @${arg.type} --${arg.arg}${
if builtins.hasAttr "required" arg && builtins.hasAttr "multi" arg then "+"
else if builtins.hasAttr "required" arg then "!"
else if builtins.hasAttr "multi" arg then "*"
else if builtins.hasAttr "rawOpts" arg then "${arg.rawOpts}"
else ""
} ${arg.help}") arguments)}
${builtins.concatStringsSep "\n" (map (arg: "argc_${arg.arg}=${arg.default or "0"}") arguments)}
eval "$(argc --argc-eval "$0" "$@")"
${text}
'';
}

0 comments on commit 14e231b

Please sign in to comment.