Skip to content

Commit d7340c2

Browse files
committed
More yml commands, environment edit command, ...
1 parent a1bcdcd commit d7340c2

File tree

14 files changed

+425
-266
lines changed

14 files changed

+425
-266
lines changed

USAGE.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,13 @@ Afterwards you can use `act.sh -E <name>` to call the given controller.
172172

173173
| Command | Description | Example |
174174
| ------- | ----------- | ------- |
175-
| source | Load environment variables | |
175+
| source | Load environment variables | `act.sh environment source myaccount` |
176176
| get | Retrieve an environment. Provide the name of the environment as parameter. | `act.sh environment get myaccount` |
177177
| delete | Delete an environment. Provide the name of the environment as parameter. | `act.sh environment delete myaccount` |
178178
| add | Add a new environment. To change the default environment, run with `-d` | `act.sh environment add -d` |
179179
| list | List all your environments | `act.sh environment list ` |
180180
| export | Export an environment into a postman environment | `act.sh environment export > output.json` |
181+
| edit | | `act.sh environment edit myaccount` |
181182

182183

183184
## eum

act.sh

+102-61
Large diffs are not rendered by default.

commands.yml

+44-44
Large diffs are not rendered by default.

commands/controller/call.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function controller_call {
88
debug "$@"
99
while getopts "X:d:F:B" opt "$@";
1010
do
11-
debug "${opt}"
1211
case "${opt}" in
1312
X)
1413
METHOD=${OPTARG}
@@ -22,11 +21,12 @@ function controller_call {
2221
B)
2322
USE_BASIC_AUTH=1
2423
;;
24+
*)
25+
debug "Invalid flag ${OPTARG} for controller_call"
26+
;;
2527
esac
2628
done
2729

28-
debug "ASDF"
29-
3030
shiftOptInd
3131
shift $SHIFTS
3232

commands/environment/edit.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
function environment_edit {
4+
if [ -x "${EDITOR}" ] || [ -x "`which "${EDITOR}"`" ] ; then
5+
${EDITOR} "${HOME}/.appdynamics/act/config.$1.sh"
6+
else
7+
error "No editor found. Please set \$EDITOR."
8+
fi
9+
}
10+
11+
register environment_edit Open an environment file in your editor
12+
describe environment_edit << EOF
13+
EOF
14+
15+
example environment_edit << EOF
16+
myaccount
17+
EOF

commands/environment/source.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ describe environment_source << EOF
1313
Load environment variables
1414
EOF
1515

16-
example environment_get << EOF
16+
example environment_source << EOF
1717
myaccount
1818
EOF

commands/help.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function _help {
44
if [ "$1" = "" ] ; then
55
read -r -d '' COMMAND_RESULT <<- EOM
6-
Usage: $SCRIPTNAME [-H <controller-host>] [-C <controller-credentials>] [-D <output-verbosity>] [-P <plugin-directory>] [-A <application-name>] <namespace> <command>\n
6+
Usage: ${USAGE_DESCRIPTION}\n
77
88
You can use the following options on a global level:\n
99
@@ -54,4 +54,4 @@ EOM
5454
fi
5555
}
5656

57-
register _help Display the global usage information
57+
register _help Display the global help.

commands/usage.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
function _usage {
4+
# shellcheck disable=SC2034
5+
read -r -d '' COMMAND_RESULT <<- EOM
6+
Usage: ${USAGE_DESCRIPTION}\n
7+
'${SCRIPTNAME} help' will list available namespaces and subcommands.
8+
See '${SCRIPTNAME} help <namespace>' to read about a specific namespace and the available subcommands
9+
EOM
10+
}
11+
12+
register _usage Display usage information.

commands/version.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22

33
function _version {
4-
COMMAND_RESULT="$ACT_VERSION ~ $ACT_LAST_COMMIT"
4+
# shellcheck disable=SC2034
5+
COMMAND_RESULT="$ACT_VERSION ~ $ACT_LAST_COMMIT (${GLOBAL_COMMANDS_COUNTER} commands)"
56
}
67

78
register _version Print the current version of $SCRIPTNAME

helpers/apiCall.sh

+22-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
function apiCall {
44
local OPTS
55
local OPTIONAL_OPTIONS=""
6+
local OPTS_TYPES=()
67
local METHOD="GET"
78

89
while getopts "X:d:" opt "$@";
@@ -37,19 +38,21 @@ function apiCall {
3738
OLDIFS=$IFS
3839
IFS="{{"
3940
for MATCH in $PAYLOAD ; do
40-
if [[ $MATCH =~ ([a-zA-Z])(\??)\}\} ]]; then
41+
if [[ $MATCH =~ ([a-zA-Z])(:[a-zA-Z0-9_-]+)?(\??)\}\} ]]; then
4142
OPT=${BASH_REMATCH[1]}:
42-
if [ "${BASH_REMATCH[2]}" = "?" ] ; then
43+
OPTS_TYPES+=(${BASH_REMATCH[1]}${BASH_REMATCH[2]})
44+
if [ "${BASH_REMATCH[3]}" = "?" ] ; then
4345
OPTIONAL_OPTIONS=${OPTIONAL_OPTIONS}${OPT}
4446
fi
4547
OPTS="${OPTS}${OPT}"
4648
fi
4749
done;
4850

4951
for MATCH in $ENDPOINT ; do
50-
if [[ $MATCH =~ ([a-zA-Z])(\??)\}\} ]]; then
52+
if [[ $MATCH =~ ([a-zA-Z])(:[a-zA-Z0-9_-]+)?(\??)\}\} ]]; then
5153
OPT=${BASH_REMATCH[1]}:
52-
if [ "${BASH_REMATCH[2]}" = "?" ] ; then
54+
OPTS_TYPES+=(${BASH_REMATCH[1]}${BASH_REMATCH[2]})
55+
if [ "${BASH_REMATCH[3]}" = "?" ] ; then
5356
OPTIONAL_OPTIONS=${OPTIONAL_OPTIONS}${OPT}
5457
fi
5558
OPTS="${OPTS}${OPT}"
@@ -58,6 +61,7 @@ function apiCall {
5861
IFS=$OLDIFS
5962

6063
debug "Identified Options: ${OPTS}"
64+
debug "Identified Types: ${OPTS_TYPES[*]}"
6165
debug "Optional Options: $OPTIONAL_OPTIONS"
6266

6367
if [ -n "$OPTS" ] ; then
@@ -67,18 +71,18 @@ function apiCall {
6771
debug "Applying $opt with $ARG"
6872
# PAYLOAD=${PAYLOAD//\$\{${opt}\}/$OPTARG}
6973
# ENDPOINT=${ENDPOINT//\$\{${opt}\}/$OPTARG}
70-
while [[ $PAYLOAD =~ \{\{$opt\??\}\} ]] ; do
74+
while [[ $PAYLOAD =~ \{\{$opt(:[a-zA-Z0-9_-]+)?\??\}\} ]] ; do
7175
PAYLOAD=${PAYLOAD//${BASH_REMATCH[0]}/$OPTARG}
7276
done;
73-
while [[ $ENDPOINT =~ \{\{$opt\??\}\} ]] ; do
77+
while [[ $ENDPOINT =~ \{\{$opt(:[a-zA-Z0-9_-]+)?\??\}\} ]] ; do
7478
ENDPOINT=${ENDPOINT//${BASH_REMATCH[0]}/$ARG}
7579
done;
7680
done
7781
shiftOptInd
7882
shift $SHIFTS
7983
fi
8084

81-
while [[ $PAYLOAD =~ \{\{([a-zA-Z])(\??)\}\} ]] ; do
85+
while [[ $PAYLOAD =~ \{\{([a-zA-Z])(:[a-zA-Z0-9_-]+)?(\??)\}\} ]] ; do
8286
if [ -z "$1" ] && [[ "${OPTIONAL_OPTIONS}" != *"${BASH_REMATCH[1]}"* ]] ; then
8387
local MISSING=${BASH_REMATCH:2:1}
8488
if [ "${MISSING}" == "a" ] && [ -n "${CONFIG_CONTROLLER_DEFAULT_APPLICATION}" ] ; then
@@ -92,13 +96,22 @@ function apiCall {
9296
shift
9397
done
9498

95-
while [[ $ENDPOINT =~ \{\{([a-zA-Z])(\??)\}\} ]] ; do
99+
while [[ $ENDPOINT =~ \{\{([a-zA-Z])(:[a-zA-Z0-9_-]+)?(\??)\}\} ]] ; do
96100
if [ -z "$1" ] && [[ "${OPTIONAL_OPTIONS}" != *"${BASH_REMATCH[1]}"* ]] ; then
97101
local MISSING=${BASH_REMATCH:2:1}
98102
if [ "${MISSING}" == "a" ] && [ -n "${CONFIG_CONTROLLER_DEFAULT_APPLICATION}" ] ; then
103+
debug "Using default application for -a: ${CONFIG_CONTROLLER_DEFAULT_APPLICATION}"
99104
ENDPOINT=${ENDPOINT//'{{a}}'/${CONFIG_CONTROLLER_DEFAULT_APPLICATION}}
100105
else
101-
error "Please provide an argument for paramater -${BASH_REMATCH:2:1}"
106+
ERROR_MESSAGE="Please provide an argument for parameter -${MISSING}"
107+
for TYPE in "${OPTS_TYPES[@]}" ;
108+
do
109+
if [[ "${TYPE}" == ${MISSING}:* ]] ; then
110+
TYPE=${TYPE//_/ }
111+
ERROR_MESSAGE="Missing ${TYPE#*:}: ${ERROR_MESSAGE}"
112+
fi
113+
done;
114+
error "${ERROR_MESSAGE}"
102115
return;
103116
fi
104117
fi

main.sh

+10-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ COLOR_RESET="\033[0m"
2727

2828
GLOBAL_COMMANDS=""
2929
GLOBAL_HELP=""
30-
GLOBAL_LONG_HELP_COUNTER=0
30+
declare -i GLOBAL_COMMANDS_COUNTER=0
3131
declare -a GLOBAL_LONG_HELP_STRINGS
3232
declare -a GLOBAL_LONG_HELP_COMMANDS
3333
declare -a GLOBAL_EXAMPLE_COMMANDS
@@ -41,6 +41,7 @@ declare -i VERBOSITY_COUNTER
4141

4242
# register namespace_command help
4343
function register {
44+
GLOBAL_COMMANDS_COUNTER+=1
4445
GLOBAL_COMMANDS="$GLOBAL_COMMANDS $1"
4546
GLOBAL_HELP="$GLOBAL_HELP\n$*"
4647
}
@@ -88,6 +89,7 @@ else
8889
fi
8990

9091
# Parse global options
92+
USAGE_DESCRIPTION="$SCRIPTNAME [-H <controller-host>] [-C <controller-credentials>] [-D <output-verbosity>] [-E <environment>] [-J <cookie-location>] [-P <plugin-directory>] [-F <controller-info-xml>] [-A <application-name>] [-O] [-v[vv]] <namespace> <command>"
9193
read -r -d '' AVAILABLE_GLOBAL_OPTIONS <<- EOM
9294
|-H <controller-host> |specify the host of the controller you want to connect to|
9395
|-C <controller-credentials> |provide the credentials for the controller. Format: user@tenant:password|
@@ -191,17 +193,21 @@ debug "CONFIG_USER_PLUGIN_DIRECTORY=$CONFIG_USER_PLUGIN_DIRECTORY"
191193

192194
recursiveSource "${CONFIG_USER_PLUGIN_DIRECTORY}"
193195

196+
197+
194198
NAMESPACE=$1
195199

196200
COMMAND_RESULT=""
197201

202+
if [ "$#" -eq 0 ] ; then
203+
_usage
198204
# Check if the namespace is used
199-
if [ "${GLOBAL_COMMANDS/${NAMESPACE}_}" != "$GLOBAL_COMMANDS" ] ; then
205+
elif [ "${GLOBAL_COMMANDS/${NAMESPACE}_}" != "$GLOBAL_COMMANDS" ] ; then
200206
debug "${NAMESPACE} has commands"
201207
COMMAND=$2
202-
if [ "$COMMAND" == "" ] || [ "$COMMAND" == "help" ]; then
208+
if [ "$COMMAND" == "" ] || [ "$COMMAND" == "help" ] ; then
203209
debug "Will display help for $NAMESPACE"
204-
_help ${NAMESPACE}
210+
echo _help ${NAMESPACE}
205211
elif [ "${GLOBAL_COMMANDS/${NAMESPACE}_${COMMAND}}" != "$GLOBAL_COMMANDS" ] ; then
206212
debug "${NAMESPACE}_${COMMAND} is a valid command"
207213
shift 2

0 commit comments

Comments
 (0)