-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage
executable file
·67 lines (59 loc) · 1.52 KB
/
manage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
set -e
SCRIPT="$(basename "$0")"
DIRNAME="$(dirname "${BASH_SOURCE[0]}")"
source "$DIRNAME/.manage"
function usage() {
echo "Usage: $SCRIPT [-h|--help] <command> [<args>]"
# if $1 is non empty, print long usage
if [ -z "$1" ]; then return; fi
echo ""
echo "Commands:"
echo " list list configurations"
echo " add Add or remove configurations to the current host"
echo " update Reload configurations of the current host"
echo " updatedeps Reload configurations of the current host"
echo " host Manage host configurations"
echo " secret Manage secrets"
echo " help Get help on commands"
echo ""
echo "Options:"
echo " -h, --help Display this message"
}
function main() {
# Ensure the workspace is initialized
initialize_workspace
# parse arguments
local cmd=""
while [ -n "$1" ]; do
case "$1" in
-h | --help)
usage long
return;;
list | add | update | updatedeps | host | secret | help)
cmd="$1"
shift
break;;
--* )
echo "$SCRIPT: invalid option: ${1:2}" >&2
usage
return 1;;
-* )
echo "$SCRIPT: invalid option: ${1:1}" >&2
usage
return 1;;
* )
echo "$SCRIPT: invalid command: ${1}" >&2
usage
return 1;;
esac
done
if [[ "x$cmd" == "x" ]]; then
usage long
return 1
fi
# load the subcommand and run it
source "$DIRNAME/.manage_$cmd"
run "$@"
}
main "$@"