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
323ARGS=()
424PARAMS=()
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)
530file=
631
32+ # Seed ARGS with a namespace from the environment if one is set
733if [ -n " $IRIS_NAMESPACE " ]; then
8- ARGS+=( -U $IRIS_NAMESPACE )
34+ ARGS+=( -U " $IRIS_NAMESPACE " )
935elif [ -n " $IRISNAMESPACE " ]; then
10- ARGS+=( -U $IRISNAMESPACE )
36+ ARGS+=( -U " $IRISNAMESPACE " )
1137fi
1238
39+ # Parse command-line arguments
1340while [[ $# -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
2267done
2368
2469if [ -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[@]} "
3282else
33- iris session iris " ${ARGS[@]} "
34- fi
83+ # Interactive mode: just open a session
84+ iris session " $INSTANCE " " ${ARGS[@]} "
85+ fi
0 commit comments