-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparty-mgr.sh
More file actions
executable file
·167 lines (141 loc) · 4.15 KB
/
Copy pathparty-mgr.sh
File metadata and controls
executable file
·167 lines (141 loc) · 4.15 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
# Party Manager Script
# Usage: ./party-mgr.sh <script-name> <input (optional)>
set -e
# Configuration
HOST="localhost"
PORT="6865"
DAR_FILE=".daml/dist/exchange-0.0.1.dar"
SCRIPT_MODULE="Scripts.PartyManagement"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
# Function to show usage
show_usage() {
echo "Party Manager - Daml Party Management CLI"
echo ""
echo "Usage: $0 <script-name> [input]"
echo ""
echo "Available scripts:"
echo " init - Initialize party registry"
echo " add <party-name> - Add a new party"
echo " remove <party-name> - Remove a party"
echo " list - List all registered parties"
echo " check <party-name> - Check if party is registered"
echo " demo - Run full demonstration"
echo ""
echo "Examples:"
echo " $0 init"
echo " $0 add Alice"
echo " $0 remove Bob"
echo " $0 list"
echo " $0 check Alice"
echo " $0 demo"
echo ""
}
# Function to check if DAR file exists
check_dar_file() {
if [ ! -f "$DAR_FILE" ]; then
print_error "DAR file not found: $DAR_FILE"
print_info "Please run 'daml build' first to create the DAR file"
exit 1
fi
}
# Function to execute daml script
execute_script() {
local script_name="$1"
local input="$2"
print_info "Executing script: $script_name"
if [ -n "$input" ]; then
print_info "With input: $input"
echo "\"$input\"" | daml script --ledger-host "$HOST" --ledger-port "$PORT" --dar "$DAR_FILE" --script-name "${SCRIPT_MODULE}:${script_name}" --input-file /dev/stdin
else
daml script --ledger-host "$HOST" --ledger-port "$PORT" --dar "$DAR_FILE" --script-name "${SCRIPT_MODULE}:${script_name}"
fi
}
# Main script logic
main() {
# Check if at least one argument is provided
if [ $# -eq 0 ]; then
show_usage
exit 1
fi
# Check if DAR file exists
check_dar_file
local command="$1"
local input="$2"
case "$command" in
"init")
print_info "Initializing party registry..."
execute_script "cmdInit"
print_success "Registry initialization completed!"
;;
"add")
if [ -z "$input" ]; then
print_error "Party name is required for 'add' command"
echo "Usage: $0 add <party-name>"
exit 1
fi
print_info "Adding party: $input"
execute_script "cmdAddParty" "$input"
print_success "Party '$input' added successfully!"
;;
"remove")
if [ -z "$input" ]; then
print_error "Party name is required for 'remove' command"
echo "Usage: $0 remove <party-name>"
exit 1
fi
print_info "Removing party: $input"
execute_script "cmdRemoveParty" "$input"
print_success "Party '$input' removed successfully!"
;;
"list")
print_info "Listing all registered parties..."
execute_script "cmdListParties"
;;
"check")
if [ -z "$input" ]; then
print_error "Party name is required for 'check' command"
echo "Usage: $0 check <party-name>"
exit 1
fi
print_info "Checking registration status for: $input"
execute_script "cmdCheckParty" "$input"
;;
"demo")
print_info "Running party management demonstration..."
execute_script "demoPartyManagement"
print_success "Demo completed!"
;;
"help" | "-h" | "--help")
show_usage
;;
*)
print_error "Unknown command: $command"
echo ""
show_usage
exit 1
;;
esac
}
# Trap errors and provide helpful messages
trap 'print_error "Script execution failed. Check the error messages above."' ERR
# Run main function with all arguments
main "$@"