diff options
author | tv <tv@krebsco.de> | 2017-09-19 20:51:07 +0200 |
---|---|---|
committer | tv <tv@krebsco.de> | 2017-09-19 20:58:23 +0200 |
commit | ab7e0c879cc0657ea7e25eb95ab89473f38c5507 (patch) | |
tree | 467dbe21fd586d317db82407107450b9656e8614 /krebs | |
parent | 9f85824da25311ec096d748798f49d09519e16aa (diff) |
withGetopt: sort getopt arguments
Diffstat (limited to 'krebs')
-rw-r--r-- | krebs/5pkgs/simple/withGetopt.nix | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/krebs/5pkgs/simple/withGetopt.nix b/krebs/5pkgs/simple/withGetopt.nix index b7bd40126..7a19ccd29 100644 --- a/krebs/5pkgs/simple/withGetopt.nix +++ b/krebs/5pkgs/simple/withGetopt.nix @@ -38,18 +38,31 @@ in writeDash wrapper-name '' wrapper_name=${shell.escape wrapper-name} + # TODO + for i in "$@"; do + case $i in + -h|--help) + ${concatStringsSep "\n" (mapAttrsToList (name: opt: /* sh */ '' + printf ' %-16s %s\n' \ + --${shell.escape opt.long} \ + ${shell.escape (opt.description or "undocumented flag")} + '') opts)} + exit + esac + done + ${concatStringsSep "\n" (mapAttrsToList (name: opt: /* sh */ '' unset ${opt.varname} '') opts)} args=$(${utillinux}/bin/getopt \ - -n "$wrapper_name" \ - -o "" \ -l ${shell.escape (concatMapStringsSep "," (opt: opt.long + optionalString (!opt.switch) ":") (filter (opt: opt.long != null) (attrValues opts)))} \ + -n "$wrapper_name" \ + -o "" \ -s sh \ -- "$@") if \test $? != 0; then exit 1; fi |