-
Notifications
You must be signed in to change notification settings - Fork 0
/
.manage_list
88 lines (80 loc) · 2.24 KB
/
.manage_list
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
function usage() {
echo "Usage: $SCRIPT list [-h|--help] [-a|--all] [-c|--current]"
echo " [-H|--hosts] [-C|--configs] [-P|--parts]"
# if $1 is non empty, print long usage
if [ -z "$1" ]; then return; fi
echo "List available hosts, configs, parts and current configuration"
echo ""
echo "Options:"
echo " -a, --all List every piece of information. Same as -c -H -C -P"
echo " This is the default behavior"
echo " -c, --current List the current host configuration"
echo " -H, --hosts List the available hosts"
echo " -C, --configs List the available configs"
echo " -P, --parts List the available parts"
echo " -h, --help Display this message"
}
function run() {
# parse arguments
local current=0 hosts=0 configs=0 parts=0
while [ -n "$1" ]; do
case "$1" in
-h | --help)
usage long
return;;
-a | --all)
current=1 hosts=1 profiles=1 configs=1
shift;;
-c | --current)
current=1
shift;;
-H | --hosts)
hosts=1
shift;;
-P | --parts)
parts=1
shift;;
-C | --configs)
configs=1
shift;;
--* )
echo "$SCRIPT: invalid option: ${1:2}" >&2
usage
return 1;;
-* )
echo "$SCRIPT: invalid option: ${1:1}" >&2
usage
return 1;;
* )
echo "$SCRIPT: invalid argument: ${1}" >&2
usage
return 1;;
esac
done
# defaults to all
if [[ $current == 0 && $hosts == 0 && $parts == 0 && $configs == 0 ]]; then
current=1 hosts=1 parts=1 configs=1
fi
local sep=""
if [[ $current == 1 ]]; then
echo "${sep}Current configuration:"
get_current_host | sed -nr "s/^([^#].*)$/ - \1/p"
sep=$'\n'
fi
if [[ $hosts == 1 ]]; then
echo "${sep}Available hosts:"
list_host_files | sed -nr "s/^([^#].*)$/ - \1/p"
sep=$'\n'
fi
if [[ $configs == 1 ]]; then
echo "${sep}Available configs:"
list_config_files | sed -nr "s/^([^#].*)$/ - \1/p"
sep=$'\n'
fi
if [[ $parts == 1 ]]; then
echo "${sep}Available parts:"
list_part_files | sed -nr "s/^([^#].*)$/ - \1/p"
sep=$'\n'
fi
}