Skip to content

Commit 98d4fec

Browse files
committed
Update gridlabd-marimo
Signed-off-by: David P. Chassin <david.chassin@me.com>
1 parent d06548f commit 98d4fec

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

subcommands/gridlabd-marimo

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
##
1010
## * `--pid`: get the process id for the notebook (if any)
1111
##
12+
## * `-R|--repo`: change marimo repository (default `arras-energy/marimo`)
13+
##
1214
## * `--upgrade`: upgrade marimo to latest version
1315
##
1416
## * `--url`: get the URL for the notebook (if any)
@@ -17,6 +19,8 @@
1719
##
1820
## * `--wait`: wait for marimo server to exit
1921
##
22+
## * `-W|--workdir`: change work directory (default `gridlabd-marimo`)
23+
##
2024
## Commands:
2125
##
2226
## * `edit NOTEBOOK`: open the notebook in the marimo editor
@@ -53,15 +57,26 @@
5357

5458
LIB=$GLD_ETC/marimo
5559
LOG=$LIB/marimo.log
56-
URL=https://raw.githubusercontent.com/arras-energy/marimo/refs/heads/main/source
5760
WAIT=no
61+
WORKDIR=gridlabd-marimo
5862

5963
E_OK=0
6064
E_SYNTAX=1
6165
E_FAIL=2
6266
E_NOTFOUND=3
6367
E_MISSING=4
6468

69+
function repo()
70+
{
71+
if [ $# -eq 0 ]; then
72+
error "missing repo name" E_MISSING
73+
fi
74+
URL=https://raw.githubusercontent.com/$1/refs/heads/main/source
75+
API=https://api.github.com/repos/$1/contents/source
76+
GIT=https://github.com/$1
77+
}
78+
repo arras-energy/marimo
79+
6580
function error()
6681
{
6782
# error MESSAGE [EXITCODE]
@@ -90,7 +105,7 @@ function index()
90105
if [ "$(gridlabd.bin --version=branch)" == "master" ]; then
91106
curl -sL -H 'Cache-Control: no-cache' $URL/.index 2>>$LOG
92107
else
93-
curl -sL -H 'Cache-Control: no-cache' https://api.github.com/repos/arras-energy/marimo/contents/source 2>>$LOG | grep '"name": ".*\.py",' | cut -f2 -d: | cut -f1 -d. | tr -cd "A-Za-z0-9_\\n"
108+
curl -sL -H 'Cache-Control: no-cache' $API 2>>$LOG | grep '"name": ".*\.py",' | cut -f2 -d: | cut -f1 -d. | tr -cd "A-Za-z0-9_\\n"
94109
fi
95110
}
96111

@@ -175,20 +190,30 @@ function edit()
175190
elif [ "$(gridlabd.bin --version=branch)" == "master" ]; then
176191
error "you must use a development version of gridlabd" E_FAIL
177192
fi
178-
if [ -d gridlabd-marimo ]; then
179-
( cd gridlabd-marimo ; git pull )
193+
if [ -d "$WORKDIR" ]; then
194+
ORIGIN=$(cd "$WORKDIR"; git remote get-url origin)
195+
if [ "$URL" != "$ORIGIN" ]; then
196+
warning "repository '$GIT' does not match '$WORKDIR' origin '$ORIGIN', unable to pull"
197+
elif [ ! -d "$WORKDIR/.git" ]; then
198+
warning "'$WORKDIR' is not a git repository (you cannot commit changes), unable to pull"
199+
else
200+
( cd "$WORKDIR" ; git pull )
201+
fi
180202
else
181-
git clone https://github.com/arras-energy/marimo gridlabd-marimo
203+
git clone $GIT "$WORKDIR" || error "clone failed" E_FAIL
182204
fi
183-
if [ ! -d gridlabd-marimo/source ]; then
205+
if [ ! -d "$WORKDIR/source" ]; then
184206
error "clone failed" E_FAIL
185207
else
186-
if [ ! -f gridlabd-marimo/source/$1.py ]; then
187-
echo "Creating gridlabd-marimo/source/$1.py"
208+
if [ ! -f "$WORKDIR/source/$1.py" ]; then
209+
echo "Creating '$WORKDIR/source/$1.py'"
188210
fi
189-
( cd gridlabd-marimo/source ; marimo edit $1.py )
211+
echo "Opening marimo notebook..." >/dev/stderr
212+
( cd "$WORKDIR/source" ; marimo edit "$1.py" )
213+
fi
214+
if [ -d "$WORKDIR/.git" ]; then
215+
warning "don't forget to add/commit/push changes to '$WORKDIR' when done editing"
190216
fi
191-
warning "don't forget to add/commit/push when done editing"
192217
}
193218

194219
function open()
@@ -228,6 +253,10 @@ while [ $# -gt 0 ]; do
228253
getpid $2
229254
shift 1
230255
;;
256+
-R|--repo)
257+
repo $2
258+
shift 1
259+
;;
231260
--upgrade)
232261
python3 -m pip install --upgrade marimo
233262
shift 1
@@ -242,6 +271,13 @@ while [ $# -gt 0 ]; do
242271
--wait)
243272
WAIT=yes
244273
;;
274+
-W|--workdir)
275+
if [ $# -eq 1 ]; then
276+
error "missing folder name" E_MISSING
277+
fi
278+
WORKDIR=$2
279+
shift
280+
;;
245281
index) # list of available apps
246282
index
247283
exit $E_OK

0 commit comments

Comments
 (0)