-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgridx
More file actions
executable file
·127 lines (109 loc) · 2.51 KB
/
Copy pathgridx
File metadata and controls
executable file
·127 lines (109 loc) · 2.51 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
die() {
printf 'ERROR: %s\n' "$*" >&2
exit 1
}
require_value() {
local opt="$1"
[[ -n "${2:-}" ]] || die "Missing value for $opt"
}
source "${SCRIPT_DIR}/lib/config.sh"
usage() {
cat <<'EOF'
Usage: gridx [global-options] <resource> <action> [args]
Resources:
auth, account, user, gateway, system, appliance,
scan, timeofuse (tou), tariff, job, token
Global options:
--help, -h Show this help
--base-url <url> Override GRIDX_BASE_URL
--account-id <id> Override GRIDX_ACCOUNT_ID
--gateway-id <id> Override GRIDX_GATEWAY_ID
--system-id <id> Override GRIDX_SYSTEM_ID
--output json|table Output format (default: json)
--dry-run Show what would happen, do not execute
--yes Confirm destructive operations
Examples:
gridx auth login
gridx system live
gridx appliance list
gridx appliance get --name heatpump
EOF
}
# Defaults
export GRIDX_OUTPUT="json"
# Parse global options
while [[ $# -gt 0 ]]; do
case "$1" in
--help|-h)
usage
exit 0
;;
--base-url)
require_value "$1" "${2:-}"
export GRIDX_BASE_URL="$2"
shift 2
;;
--account-id)
require_value "$1" "${2:-}"
export GRIDX_ACCOUNT_ID="$2"
shift 2
;;
--gateway-id)
require_value "$1" "${2:-}"
export GRIDX_GATEWAY_ID="$2"
shift 2
;;
--system-id)
require_value "$1" "${2:-}"
export GRIDX_SYSTEM_ID="$2"
shift 2
;;
--output)
require_value "$1" "${2:-}"
[[ "$2" == "json" || "$2" == "table" ]] || die "Invalid output format: $2 (expected json or table)"
export GRIDX_OUTPUT="$2"
shift 2
;;
--dry-run)
export GRIDX_DRY_RUN="true"
shift
;;
--yes)
export GRIDX_CONFIRM="true"
shift
;;
--)
shift
break
;;
--*)
die "Unknown global option: $1"
;;
*)
break
;;
esac
done
if [[ $# -lt 1 ]]; then
usage
exit 0
fi
if [[ $# -gt 0 && "$1" == -* ]]; then
die "Unknown option: $1"
fi
RESOURCE="$1"
shift
ACTION="${1:-help}"
shift || true
COMMAND_FILE="${SCRIPT_DIR}/commands/${RESOURCE}.sh"
if [[ ! -f "$COMMAND_FILE" ]]; then
die "Unknown resource: $RESOURCE. Run 'gridx --help' for available resources."
fi
load_env
validate_environment
export GRIDX_RESOURCE="$RESOURCE"
export GRIDX_ACTION="$ACTION"
exec bash "$COMMAND_FILE" "$ACTION" "$@"