aboutsummaryrefslogtreecommitdiffstats
path: root/ves.sh
diff options
context:
space:
mode:
Diffstat (limited to 'ves.sh')
-rwxr-xr-x[-rw-r--r--]ves.sh105
1 files changed, 82 insertions, 23 deletions
diff --git a/ves.sh b/ves.sh
index 28325db..99049a4 100644..100755
--- a/ves.sh
+++ b/ves.sh
@@ -1,60 +1,119 @@
#!/bin/sh
+#
+# Global wrapper function dispatching to the various sh-ves subcommands.
+#
ves() {
- if [ "$#" -lt 1 ]; then
- printf "ERROR: Please specify a command.\n"
- return
+ if [ -z "$SH_VES_INIT" ]; then
+ printf "ERROR: sh-ves is not initialized. Source ves-init.sh first.\n" >&2
+ return 1
fi
+ if [ "$#" -lt 1 ]; then
+ printf "ERROR: Please specify a command.\n" >&2
+ ves_help >&2
+ return 1
+ fi
# extract the appropriate command
case $1 in
create)
shift
- ves_create $@
- break
+ ves_create "$@"
;;
delete)
shift
- ves_delete $@
- break
+ ves_delete "$@"
;;
var-add)
shift
- ves_var_add $@
- break
+ ves_var_add "$@"
;;
var-rm)
shift
- ves_var_rm $@
- break
+ ves_var_rm "$@"
;;
export)
shift
- ves_export $@
- break
+ ves_export "$@"
+ ;;
+ unset)
+ shift
+ ves_unset "$@"
+ ;;
+ show)
+ shift
+ ves_show "$@"
+ ;;
+ copy)
+ shift
+ ves_copy "$@"
+ ;;
+ rename)
+ shift
+ ves_rename "$@"
+ ;;
+ run)
+ shift
+ ves_run "$@"
+ ;;
+ switch)
+ shift
+ ves_switch "$@"
;;
list)
shift
- "$SHVES_BIN"/ves-list.sh $@
- break
+ ves_list "$@"
+ ;;
+ envs)
+ shift
+ ves_envs "$@"
;;
activate)
shift
- ves_activate $@
- break
+ ves_activate "$@"
;;
deactivate)
shift
- ves_deactivate $@
- break
+ ves_deactivate "$@"
;;
prompt)
shift
- . $SHVES_BIN/ves-prompt.sh $@
- break
+ "$SHVES_BIN"/ves-prompt.sh "$@"
+ ;;
+ help|--help|-h)
+ ves_help
;;
*)
- printf "ERROR: Invalid command [%s]\n" $1 > /dev/stderr
- return
+ printf "ERROR: Invalid command [%s]\n" "$1" >&2
+ ves_help >&2
+ return 1
+ ;;
esac
}
+
+ves_help() {
+ cat <<'EOF'
+usage: ves <command> [arguments]
+
+commands:
+ create [--override] <name> create a new environment
+ delete <name> delete an environment
+ copy <src> <dst> copy an environment
+ rename <old> <new> rename an environment
+ activate <name> activate an environment
+ deactivate deactivate the active environment
+ switch <name> deactivate, then activate <name>
+ run <name> <command...> run a command inside an environment
+ export [--env=<name>] <var> <val> set a variable in an environment
+ unset [--env=<name>] <var> remove a variable from an environment
+ show [<name>] show the variables of an environment
+ var-add [--env=<name>] [--append] <var> <val>
+ prepend (or append) an entry to a
+ path-like variable
+ var-rm [--env=<name>] <var> <val> remove an entry from a path-like variable
+ list [--index] <var> list the entries of a path-like variable
+ envs list all environments
+ prompt [symbol] print a prompt fragment for PS1
+ help show this message
+EOF
+}