shell: use withGetopts for parse-target
This commit is contained in:
parent
16e6046544
commit
3005faecd4
20
shell.nix
20
shell.nix
@ -111,19 +111,13 @@ let
|
|||||||
|
|
||||||
# usage: parse-target [--default=TARGET] TARGET
|
# usage: parse-target [--default=TARGET] TARGET
|
||||||
# TARGET = [USER@]HOST[:PORT][/PATH]
|
# TARGET = [USER@]HOST[:PORT][/PATH]
|
||||||
cmds.parse-target = pkgs.writeDash "cmds.parse-target" ''
|
cmds.parse-target = pkgs.withGetopt {
|
||||||
|
default_target = {
|
||||||
|
long = "default";
|
||||||
|
short = "d";
|
||||||
|
};
|
||||||
|
} (opts: pkgs.writeDash "cmds.parse-target" ''
|
||||||
set -efu
|
set -efu
|
||||||
args=$(${pkgs.utillinux}/bin/getopt -n "$0" -s sh \
|
|
||||||
-o d: \
|
|
||||||
-l default: \
|
|
||||||
-- "$@")
|
|
||||||
if \test $? != 0; then exit 1; fi
|
|
||||||
eval set -- "$args"
|
|
||||||
default_target=
|
|
||||||
while :; do case $1 in
|
|
||||||
-d|--default) default_target=$2; shift 2;;
|
|
||||||
--) shift; break;;
|
|
||||||
esac; done
|
|
||||||
target=$1; shift
|
target=$1; shift
|
||||||
for arg; do echo "$0: bad argument: $arg" >&2; done
|
for arg; do echo "$0: bad argument: $arg" >&2; done
|
||||||
if \test $# != 0; then exit 2; fi
|
if \test $# != 0; then exit 2; fi
|
||||||
@ -142,7 +136,7 @@ let
|
|||||||
($default_target | parse) + ($target | parse | sanitize) |
|
($default_target | parse) + ($target | parse | sanitize) |
|
||||||
. + { local: (.user == env.LOGNAME and .host == env.HOSTNAME) }
|
. + { local: (.user == env.LOGNAME and .host == env.HOSTNAME) }
|
||||||
''}
|
''}
|
||||||
'';
|
'');
|
||||||
|
|
||||||
# usage: quote [ARGS...]
|
# usage: quote [ARGS...]
|
||||||
cmds.quote = pkgs.writeDash "cmds.quote" ''
|
cmds.quote = pkgs.writeDash "cmds.quote" ''
|
||||||
|
Loading…
Reference in New Issue
Block a user