Skip to content

Commit 373a05e

Browse files
committed
Add documentation, -h help flag, and -i IRIS instance flag
1 parent 1a7f2e9 commit 373a05e

3 files changed

Lines changed: 117 additions & 35 deletions

File tree

ipm

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,73 @@
11
#!/bin/bash
22

3-
# ipm: convenience wrapper to run a ZPM command in an IRIS session
4-
# Usage examples:
5-
# ipm isc.genai test -only
6-
# ipm -U PLAZA isc.genai test -only
3+
# ipm: convenience wrapper to run an IPM command in an IRIS session
4+
#
5+
# Usage: ipm [-U <namespace>] [-i <instance>] <IPM command and args...>
6+
#
7+
# Options:
8+
# -U <namespace> IRIS namespace to run in (default: USER, or $IRIS_NAMESPACE / $IRISNAMESPACE)
9+
# -i <instance> IRIS instance name (default: $ISC_PACKAGE_INSTANCENAME, then "iris")
10+
# -h, --help Show this help message
11+
#
12+
# Examples:
13+
# ipm list # list all installed modules
14+
# ipm install MyModule # install a module from the registry
15+
# ipm test MyModule -only # run tests for a module
16+
# ipm -U USER list # run in a specific namespace
17+
# ipm -i iris list # run against a specific IRIS instance
718

19+
# Arrays to accumulate iris session flags and the IPM command tokens
820
ARGS=()
921
CMD=()
1022

11-
# Allow namespace via env like iriscli
23+
# Default instance: prefer the container-standard env var, fall back to "iris"
24+
INSTANCE="${ISC_PACKAGE_INSTANCENAME:-iris}"
25+
26+
# Seed ARGS with a namespace from the environment if one is set
1227
if [ -n "$IRIS_NAMESPACE" ]; then
1328
ARGS+=( -U "$IRIS_NAMESPACE" )
1429
elif [ -n "$IRISNAMESPACE" ]; then
1530
ARGS+=( -U "$IRISNAMESPACE" )
1631
fi
1732

18-
# Optional leading -U <ns>
19-
if [ "$1" = "-U" ] && [ -n "$2" ]; then
20-
ARGS+=( -U "$2" )
21-
shift 2
22-
fi
23-
24-
# Remaining args compose the ZPM command string
33+
# Parse command-line arguments
2534
while [[ $# -gt 0 ]]; do
26-
CMD+=( "$1" )
27-
shift
35+
case "$1" in
36+
-h|--help)
37+
# Print the comment block at the top of this file, stripping the leading "# "
38+
sed -n '3,17p' "$0" | sed 's/^# \?//'
39+
exit 0
40+
;;
41+
-U)
42+
# Explicit -U overrides any namespace set from the environment
43+
ARGS=( -U "$2" )
44+
shift 2
45+
;;
46+
-i)
47+
INSTANCE="$2"
48+
shift 2
49+
;;
50+
*)
51+
# All remaining arguments form the IPM command string
52+
CMD+=( "$1" )
53+
shift
54+
;;
55+
esac
2856
done
2957

3058
if [ ${#CMD[@]} -eq 0 ]; then
31-
echo "Usage: ipm [ -U <NAMESPACE> ] <zpm command and args...>" >&2
59+
echo "Usage: ipm [-U <namespace>] [-i <instance>] <IPM command and args...>" >&2
60+
echo " ipm --help for more information" >&2
3261
exit 1
3362
fi
3463

35-
# Join CMD array into a single string
64+
# Join the CMD array into a single string for the ObjectScript zpm call
3665
CMDSTR="${CMD[*]}"
37-
# Escape quotes for ObjectScript string literal
66+
# Escape any double-quotes in the command string ("" is a literal " in ObjectScript strings)
3867
CMDSTR_ESC=${CMDSTR//\"/\"\"}
3968

40-
# Build an OS snippet and feed to iris session
69+
# Pipe the zpm command into iris session; :1:1 flags suppress the session banner and prompt
4170
(
4271
echo "zpm \"${CMDSTR_ESC}\":1:1"
4372
echo "halt"
44-
) | iris session ${ISC_PACKAGE_INSTANCENAME:-iris} "${ARGS[@]}"
73+
) | iris session "$INSTANCE" "${ARGS[@]}"

iriscli

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,85 @@
11
#!/bin/bash
22

3+
# iriscli: convenience wrapper to open an IRIS terminal session or run a script file
4+
#
5+
# Usage: iriscli [-U <namespace>] [-i <instance>] [<script file> [param...]]
6+
#
7+
# Options:
8+
# -U <namespace> IRIS namespace to connect to (default: $IRIS_NAMESPACE / $IRISNAMESPACE)
9+
# -i <instance> IRIS instance name (default: $ISC_PACKAGE_INSTANCENAME, then "iris")
10+
# -h, --help Show this help message
11+
#
12+
# Examples:
13+
# iriscli # interactive session
14+
# iriscli -U USER # interactive session in USER namespace
15+
# iriscli -i iris # interactive session on a named instance
16+
# iriscli /path/to/script.script # run a script file and halt
17+
# iriscli /path/to/script.script arg1 arg2 # run with params exposed as params(1), params(2)
18+
#
19+
# Script file format: ObjectScript, one command per line; blank lines and lines
20+
# starting with ;, #, or // are ignored.
21+
22+
# Arrays to accumulate iris session flags and script parameters
323
ARGS=()
424
PARAMS=()
25+
26+
# Default instance: prefer the container-standard env var, fall back to "iris"
27+
INSTANCE="${ISC_PACKAGE_INSTANCENAME:-iris}"
28+
29+
# Path to the script file to run (empty = interactive mode)
530
file=
631

32+
# Seed ARGS with a namespace from the environment if one is set
733
if [ -n "$IRIS_NAMESPACE" ]; then
8-
ARGS+=( -U $IRIS_NAMESPACE )
34+
ARGS+=( -U "$IRIS_NAMESPACE" )
935
elif [ -n "$IRISNAMESPACE" ]; then
10-
ARGS+=( -U $IRISNAMESPACE )
36+
ARGS+=( -U "$IRISNAMESPACE" )
1137
fi
1238

39+
# Parse command-line arguments
1340
while [[ $# -gt 0 ]]; do
14-
if [ -x $1 ]; then
15-
file=$1
16-
elif [ -z "$file" ]; then
17-
ARGS+=("$1")
18-
else
19-
PARAMS+=("$1")
20-
fi
21-
shift
41+
case "$1" in
42+
-h|--help)
43+
# Print the comment block at the top of this file, stripping the leading "# "
44+
sed -n '3,20p' "$0" | sed 's/^# \?//'
45+
exit 0
46+
;;
47+
-U)
48+
# Explicit -U overrides any namespace set from the environment
49+
ARGS=( -U "$2" )
50+
shift 2
51+
;;
52+
-i)
53+
INSTANCE="$2"
54+
shift 2
55+
;;
56+
*)
57+
# First non-flag argument that is an existing file becomes the script to run;
58+
# everything after that is treated as a parameter passed into the script.
59+
if [ -z "$file" ] && [ -f "$1" ]; then
60+
file=$1
61+
else
62+
PARAMS+=("$1")
63+
fi
64+
shift
65+
;;
66+
esac
2267
done
2368

2469
if [ -n "$file" ]; then
70+
# Script mode: pipe ObjectScript into iris session and halt when done.
71+
# The subshell groups all input so iris session receives it as a single stdin stream.
2572
(
26-
for param in ${PARAMS[@]}; do
73+
# Expose any extra arguments as params(1), params(2), ... in ObjectScript.
74+
# Double-quotes inside param values are escaped by doubling them ("" is a literal " in ObjectScript strings).
75+
for param in "${PARAMS[@]}"; do
2776
echo "Set params(\$i(params)) = \"${param//\"/\"\"}\""
2877
done
29-
egrep -v '^(;|#|//)|^$' $file;
78+
# Strip comment lines (starting with ;, #, //) and blank lines before feeding to IRIS
79+
grep -Ev '^(;|#|//)' "$file" | grep -v '^$'
3080
echo halt
31-
) | iris session $ISC_PACKAGE_INSTANCENAME "${ARGS[@]}"
81+
) | iris session "$INSTANCE" "${ARGS[@]}"
3282
else
33-
iris session iris "${ARGS[@]}"
34-
fi
83+
# Interactive mode: just open a session
84+
iris session "$INSTANCE" "${ARGS[@]}"
85+
fi

preload/cls/IPM/Installer.cls

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Include %IPM.Common
2+
13
Class IPM.Installer Extends %Projection.AbstractProjection
24
{
35

@@ -487,7 +489,7 @@ ClassMethod InstallScripts() As %Status
487489
}
488490
try {
489491
// The scripts are staged under ${ipmdir}bin/ by <FileCopy> in module.xml.
490-
set module = ##class(%IPM.Storage.Module).NameOpen("ZPM", , .openSC)
492+
set module = ##class(%IPM.Storage.Module).NameOpen($$$IPMModuleName, , .openSC)
491493
$$$ThrowOnError(openSC)
492494
if '$isobject(module) {
493495
write !,"Could not resolve module directory for script installation."

0 commit comments

Comments
 (0)