Skip to content

Commit 8a0d36c

Browse files
committed
chore: code cleanup to avoid too much magic in the bin/codeflare shell script
Push this complexity to a kui catchall command registration. We want `codeflare ml/codeflare` to open in guide mode. We do this, in this PR, by using a Kui catchall, catching all unknown command lines that start with `codeflare ...`. With this in place, we can remove some of the junk in the bin/codeflare shell script. This PR also fixes a number of bugs with handling of spaces in filepaths. Why add this to this PR? Because we need to update bin/codeflare to use "$@" to fix spaces... This requires us to add `codeflare ` as a prefix, which leads to the catchall ...
1 parent 6b98b4e commit 8a0d36c

File tree

17 files changed

+69
-50
lines changed

17 files changed

+69
-50
lines changed

bin/codeflare

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,38 +116,24 @@ do
116116
case $opt in
117117
d) use_docker=1; continue;;
118118
u) do_cli=0; continue;;
119-
s) GUIDEBOOK_STORE=$OPTARG; continue;;
120-
*) EXTRAPREFIX="$EXTRAPREFIX -$opt"; continue;;
119+
s) export GUIDEBOOK_STORE=$OPTARG; continue;;
120+
*) continue;;
121121
esac
122122
done
123-
shift $((OPTIND-1))
123+
# shift $((OPTIND-1))
124124

125125
if [ $use_docker = 1 ]; then
126126
# launch inside a docker container
127127
exec docker run -it --entrypoint ${ENTRYPOINT-codeflare} --rm -v /tmp:/tmp -v ~/.aws:/home/codeflare/.aws -v ~/.bluemix:/home/codeflare/.bluemix -v ~/.kube:/home/codeflare/.kube -e KUBECONFIG=$(echo $KUBECONFIG | sed "s/$USER/codeflare/g" | sed 's/Users/home/g') ghcr.io/project-codeflare/codeflare-cli -- $*
128128
fi
129129

130-
if ([ $do_cli = 1 ] && [ $# = 0 ]) || ([ $# = 1 ] && [ "$1" != "version" ] && [ "$1" != "attach" ]); then
131-
# TODO make this a kui command catchall
132-
# use the "guide" command if none was given
133-
EXTRAPREFIX="$EXTRAPREFIX guide"
134-
fi
135-
136130
if [ "$do_cli" = "1" ]; then
137131
# launch headless version; here, we use madwizard directly, but
138132
# using electron as the nodejs binary (this is what
139133
# ELECTRON_RUN_AS_NODE does for us)
140134
export KUI_HEADLESS=true
141135
export KUI_S3=false # we don't need plugin-s3 capabilities when in headless mode
142136
export ELECTRON_RUN_AS_NODE=true
143-
# export MWSTORE="$GUIDEBOOK_STORE"
144-
# exec "$NODE" \
145-
# --experimental-specifier-resolution=node --no-warnings --experimental-import-meta-resolve \
146-
# "$HEADLESS"/../../node_modules/madwizard/bin/madwizard.js \
147-
# $*
148-
elif [ $# -gt 0 ]; then
149-
# tell the command handlers to run in UI mode
150-
EXTRAPREFIX="$EXTRAPREFIX -u"
151137
fi
152138

153139
# Linux may not have the prereqs needed to run Electron
@@ -176,4 +162,4 @@ fi
176162
trap 'pkill -P $$; exit 1;' TERM INT
177163

178164
# otherwise, we launch the UI version
179-
"$NODE" "$HEADLESS"/codeflare.min.js -- $EXTRAPREFIX $*
165+
"$NODE" "$HEADLESS"/codeflare.min.js -- codeflare $EXTRAPREFIX "$@"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"postinstall": "npm run compile",
4040
"format": "prettier --write '**/*.{scss,css,html,js,json,md,ts,tsx}'",
4141
"lint": "eslint . --ext '**/*.{js,ts,tsx}'",
42-
"open": "./bin/codeflare -u",
42+
"open": "./bin/codeflare hello",
4343
"start": "WATCH_ARGS='-open' npm run watch",
4444
"mirror": "cross-env rm -rf tmp && cross-env git clone --depth=1 https://github.com/guidebooks/store.git $PWD/tmp/store && cross-env madwizard mirror $PWD/tmp/store/guidebooks $PWD/store && rm -rf tmp",
4545
"mirror-if-needed": "if [ ! -d ./store ]; then npm run mirror; fi",

plugins/plugin-client-default/notebooks/dashboard-summary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
execute: now
66
outputOnly: true
77
---
8-
description $LOGDIR/job.json
8+
codeflare description $LOGDIR/job.json
99
```

plugins/plugin-client-default/notebooks/dashboard.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ layout:
2424
execute: now
2525
outputOnly: true
2626
---
27-
description application "$LOGDIR"
27+
codeflare description application "$LOGDIR"
2828
```
2929

3030
=== "Workers"
@@ -34,7 +34,7 @@ layout:
3434
execute: now
3535
outputOnly: true
3636
---
37-
description workers "$LOGDIR"
37+
codeflare description workers "$LOGDIR"
3838
```
3939

4040
---
@@ -87,7 +87,7 @@ layout:
8787
maximize: true
8888
outputOnly: true
8989
---
90-
chart all "${LOGDIR}"
90+
codeflare chart all "${LOGDIR}"
9191
```
9292

9393
---
@@ -98,5 +98,5 @@ layout:
9898
execute: now
9999
outputOnly: true
100100
---
101-
chart events "${LOGDIR}"
101+
codeflare chart events "${LOGDIR}"
102102
```

plugins/plugin-client-default/src/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ export default function renderMain(props: KuiProps) {
5959
initialTabTitle="Welcome"
6060
isPopup={false}
6161
quietExecCommand={false}
62-
commandLine={
63-
process.env.RUNNING_KUI_TEST
64-
? undefined
65-
: props.commandLine || ["commentary", "--readonly", "-f", "/kui/client/welcome.md"]
66-
}
62+
commandLine={process.env.RUNNING_KUI_TEST ? undefined : props.commandLine || ["codeflare", "hello"]}
6763
>
6864
<ContextWidgets>
6965
<GitHubIcon />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2022 The Kubernetes Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { doMadwizard } from "@kui-shell/plugin-madwizard"
18+
19+
export default doMadwizard(true, "guide", true)

plugins/plugin-codeflare/src/controller/charts/all.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async function offline(filepath: string, REPL: Arguments["REPL"]): Promise<React
8686
*
8787
*/
8888
export default async function all(args: Arguments) {
89-
const filepath = args.argvNoOptions[2]
89+
const filepath = args.argvNoOptions[3]
9090
if (!filepath) {
9191
throw new Error(`Usage chart all ${filepath}`)
9292
}

plugins/plugin-codeflare/src/controller/charts/gpu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function chart(logs: Awaited<ReturnType<typeof parse>>): ReactResponse {
8282
}
8383

8484
export default async function chartCmd(args: Arguments) {
85-
const filepath = args.argvNoOptions[2]
85+
const filepath = args.argvNoOptions[3]
8686
if (!filepath) {
8787
throw new Error(`Usage chart vmstat ${filepath}`)
8888
}

plugins/plugin-codeflare/src/controller/charts/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import { Registrar } from "@kui-shell/core"
1818

1919
/** Register Kui Commands */
2020
export default function registerCodeflareCommands(registrar: Registrar) {
21-
registrar.listen("/chart/gpu", (args) => import("./gpu").then((_) => _.default(args)), { needsUI: true })
22-
registrar.listen("/chart/vmstat", (args) => import("./vmstat").then((_) => _.default(args)), { needsUI: true })
23-
registrar.listen("/chart/all", (args) => import("./all").then((_) => _.default(args)), { needsUI: true })
21+
registrar.listen("/codeflare/chart/gpu", (args) => import("./gpu").then((_) => _.default(args)), { needsUI: true })
22+
registrar.listen("/codeflare/chart/vmstat", (args) => import("./vmstat").then((_) => _.default(args)), {
23+
needsUI: true,
24+
})
25+
registrar.listen("/codeflare/chart/all", (args) => import("./all").then((_) => _.default(args)), { needsUI: true })
2426
}

plugins/plugin-codeflare/src/controller/charts/vmstat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function chart(logs: Awaited<ReturnType<typeof parse>>): ReactResponse {
8181
}
8282

8383
export default async function chartCmd(args: Arguments) {
84-
const filepath = args.argvNoOptions[2]
84+
const filepath = args.argvNoOptions[3]
8585
if (!filepath) {
8686
throw new Error(`Usage chart vmstat ${filepath}`)
8787
}

0 commit comments

Comments
 (0)