diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2015-09-14 17:43:27 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2015-09-14 17:43:45 +0200 |
commit | 838682663a84a4d55ab145c312bad5355022432e (patch) | |
tree | bd50cf17eca53f460699dab7a6cc57c49e49e69c | |
parent | 4fa7e95e7f56f0c27b944e8f3b649b98dfaf87eb (diff) |
Add callback helper for builtins
-rwxr-xr-x | nix-script-repl.sh | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/nix-script-repl.sh b/nix-script-repl.sh index 21252d5..2582450 100755 --- a/nix-script-repl.sh +++ b/nix-script-repl.sh @@ -66,12 +66,27 @@ __list() { caller_util_list_subcommands_for "nix-script" } +__builtin__() { + local str=$1; shift + local cmd=$1; shift + local args=$* + + if [[ $COMMAND =~ $str ]] + then + $cmd $args && prompt + return 1 + else + return 0 + fi +} + prompt while read COMMAND ARGS do [[ $COMMAND =~ "quit" || $COMMAND =~ "exit" ]] && break - [[ $COMMAND =~ "help" ]] && usage && prompt && continue - [[ $COMMAND =~ "list" ]] && __list && prompt && continue + + __builtin__ "help" usage $ARGS || continue + __builtin__ "list" __list $ARGS || continue dbg "Got '$COMMAND' with args '$ARGS'" stdout "Searching for script for '$COMMAND'" |