-
Notifications
You must be signed in to change notification settings - Fork 1
/
orgwide
executable file
·74 lines (65 loc) · 1.18 KB
/
orgwide
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
#! /usr/bin/env bash
VERSION="0.0.1"
CMD=$(basename $0)
ARGS=""
usage(){
AVAILABLE=$(compgen -c $ORG-)
echo -e "\nUsage:\n $ORG [options] <subcommand> [subcommand options] <args>\n"
echo " Options:"
echo " -h, --help Display this help message"
echo " -v, --version Display version information"
echo -e "\nAvailable subcommands:\n${AVAILABLE//$CMD-/ - }\n"
}
ORG=$( echo `basename "$0"` | cut -d'-' -f1 )
if [[ $# -eq 0 ]]; then
usage
exit 1
fi
# Convert known long options to short options
for arg in "$@"; do
shift
case "$arg" in
--help)
set -- "$@" "-h"
;;
--version)
set -- "$@" "-v"
;;
*)
set -- "$@" "$arg"
;;
esac
done
# Reset to beginning of arguments
OPTIND=1
# Process option flags
while getopts ":hv" opt; do
case "$opt" in
h )
usage
exit 0
;;
v )
echo "version $VERSION"
exit 0
;;
\? )
echo -e "Unrecognized option: -$OPTARG\n"
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
# Find subcommands and subcommand arguments
SUB=$1; shift
for var in "$@"; do
if [[ $var == \-* ]]
then
ARGS+="$var "
else
ARGS+="\"$var\" "
fi
done
# Send to subcommand
eval "${CMD} ${SUB} ${ARGS}"