Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit bc5eca3

Browse files
committed
Support fish shell completion
Signed-off-by: Marc Khouzam <[email protected]>
1 parent c7f0b5e commit bc5eca3

File tree

1 file changed

+97
-18
lines changed

1 file changed

+97
-18
lines changed

scripts/completion-tests/completionTests.sh

Lines changed: 97 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,31 +106,38 @@ cat > ${PLUGIN_DIR}/plugin.complete << EOF
106106
#!/usr/bin/env sh
107107
108108
if [ "\$2" = "config" ]; then
109-
echo "case-config"
110-
echo "gryffindor slytherin ravenclaw hufflepuff"
111-
echo ":0"
109+
echo case-config
110+
echo gryffindor
111+
echo slytherin
112+
echo ravenclaw
113+
echo hufflepuff
114+
echo :0
112115
exit
113116
fi
114117
115118
if [ "\$HELM_NAMESPACE" != "default" ]; then
116-
echo "case-ns"
119+
echo case-ns
117120
# Check the namespace flag is not passed
118-
echo "\$1"
121+
echo \$1
119122
# Check plugin variables are set
120-
echo "\$HELM_NAMESPACE"
121-
echo ":4"
123+
echo \$HELM_NAMESPACE
124+
echo :4
122125
exit
123126
fi
124127
125128
if [ "\$2" = -s ]; then
126-
echo "case-flag"
127-
echo "lucius draco dobby"
128-
echo ":4"
129+
echo case-flag
130+
echo lucius
131+
echo draco
132+
echo dobby
133+
echo :4
129134
exit
130135
fi
131136
132137
# Check missing directive
133-
echo "hermione harry ron"
138+
echo hermione
139+
echo harry
140+
echo ron
134141
EOF
135142
chmod u+x ${PLUGIN_DIR}/plugin.complete
136143

@@ -146,6 +153,30 @@ version: "0.7.1"
146153
description: "Push chart package to ChartMuseum"
147154
EOF
148155

156+
# A plugin's static completion file without a dynamic completion file
157+
cat > ${PLUGIN_DIR}/completion.yaml << EOF
158+
commands:
159+
- name: cleanup
160+
flags:
161+
- r
162+
- label
163+
- cleanup
164+
- s
165+
- storage
166+
- name: convert
167+
flags:
168+
- l
169+
- label
170+
- s
171+
- storage
172+
- t
173+
- name: move
174+
commands:
175+
- name: config
176+
flags:
177+
- dry-run
178+
EOF
179+
149180
###########
150181
# Plugin 3
151182
###########
@@ -158,6 +189,46 @@ version: "0.3.0"
158189
description: "Push helm charts to artifactory"
159190
EOF
160191

192+
# A plugin's dynamic completion file without a static completion file
193+
cat > ${PLUGIN_DIR}/plugin.complete << EOF
194+
#!/usr/bin/env sh
195+
196+
if [ "\$2" = "config" ]; then
197+
echo case-config
198+
echo gryffindor
199+
echo slytherin
200+
echo ravenclaw
201+
echo hufflepuff
202+
echo :0
203+
exit
204+
fi
205+
206+
if [ "\$HELM_NAMESPACE" != "default" ]; then
207+
echo case-ns
208+
# Check the namespace flag is not passed
209+
echo \$1
210+
# Check plugin variables are set
211+
echo \$HELM_NAMESPACE
212+
echo :4
213+
exit
214+
fi
215+
216+
if [ "\$2" = -s ]; then
217+
echo case-flag
218+
echo lucius
219+
echo draco
220+
echo dobby
221+
echo :4
222+
exit
223+
fi
224+
225+
# Check missing directive
226+
echo hermione
227+
echo harry
228+
echo ron
229+
EOF
230+
chmod u+x ${PLUGIN_DIR}/plugin.complete
231+
161232
helm plugin list
162233

163234
# Source the completion script after setting things up, so it can
@@ -207,7 +278,7 @@ else
207278
_completionTests_verifyCompletion "helm get " "all hooks manifest notes values"
208279
fi
209280
_completionTests_verifyCompletion "helm get h" "hooks"
210-
_completionTests_verifyCompletion "helm completion " "bash zsh"
281+
_completionTests_verifyCompletion "helm completion " "bash zsh fish"
211282
_completionTests_verifyCompletion "helm completion z" "zsh"
212283
_completionTests_verifyCompletion "helm plugin " "install list uninstall update"
213284
_completionTests_verifyCompletion "helm plugin u" "uninstall update"
@@ -225,13 +296,13 @@ _completionTests_verifyCompletion "helm plugin --namespace ns " "install list un
225296
_completionTests_verifyCompletion "helm plugin --namespace ns u" "uninstall update"
226297

227298
# With validArgs
228-
_completionTests_verifyCompletion "helm completion " "bash zsh"
299+
_completionTests_verifyCompletion "helm completion " "bash zsh fish"
229300
_completionTests_verifyCompletion "helm completion z" "zsh"
230-
_completionTests_verifyCompletion "helm --debug completion " "bash zsh"
301+
_completionTests_verifyCompletion "helm --debug completion " "bash zsh fish"
231302
_completionTests_verifyCompletion "helm --debug completion z" "zsh"
232-
_completionTests_verifyCompletion "helm -n ns completion " "bash zsh"
303+
_completionTests_verifyCompletion "helm -n ns completion " "bash zsh fish"
233304
_completionTests_verifyCompletion "helm -n ns completion z" "zsh"
234-
_completionTests_verifyCompletion "helm --namespace ns completion " "bash zsh"
305+
_completionTests_verifyCompletion "helm --namespace ns completion " "bash zsh fish"
235306
_completionTests_verifyCompletion "helm --namespace ns completion z" "zsh"
236307

237308
# Completion of flags
@@ -292,16 +363,21 @@ _completionTests_verifyCompletion "helm ls" ""
292363
_completionTests_verifyCompletion "helm dependenci" ""
293364

294365
# Static completion for plugins
295-
_completionTests_verifyCompletion "helm push " ""
296366
_completionTests_verifyCompletion "helm 2to3 " "cleanup convert move"
297367
_completionTests_verifyCompletion "helm 2to3 c" "cleanup convert"
298368
_completionTests_verifyCompletion "helm 2to3 move " "config"
369+
_completionTests_verifyCompletion "helm push " "cleanup convert move"
370+
_completionTests_verifyCompletion "helm push c" "cleanup convert"
371+
_completionTests_verifyCompletion "helm push move " "config"
299372

300373
_completionTests_verifyCompletion "helm 2to3 cleanup -" "$allHelmGlobalFlags -r -s --label --cleanup --storage"
374+
_completionTests_verifyCompletion "helm push cleanup -" "$allHelmGlobalFlags -r -s --label --cleanup --storage"
301375
# For plugin completion, when there are more short flags than long flags, a long flag is created for the extra short flags
302376
# So here we expect the extra --t
303377
_completionTests_verifyCompletion "helm 2to3 convert -" "$allHelmGlobalFlags -l -s -t --t --label --storage"
304378
_completionTests_verifyCompletion "helm 2to3 move config --" "$allHelmLongFlags --dry-run"
379+
_completionTests_verifyCompletion "helm push convert -" "$allHelmGlobalFlags -l -s -t --t --label --storage"
380+
_completionTests_verifyCompletion "helm push move config --" "$allHelmLongFlags --dry-run"
305381

306382
#####################
307383
# Dynamic completions
@@ -442,11 +518,14 @@ if [ ! -z ${ROBOT_HELM_V3} ]; then
442518
fi
443519

444520
# Dynamic completion for plugins
445-
_completionTests_verifyCompletion "helm push " ""
446521
_completionTests_verifyCompletion "helm 2to3 move config g" "gryffindor"
447522
_completionTests_verifyCompletion "helm 2to3 -n dumbledore convert " "case-ns convert dumbledore"
448523
_completionTests_verifyCompletion "helm 2to3 convert -s flag d" "dobby draco"
449524
_completionTests_verifyCompletion "helm 2to3 convert " "hermione harry ron"
525+
_completionTests_verifyCompletion "helm push-artifactory move config g" "gryffindor"
526+
_completionTests_verifyCompletion "helm push-artifactory -n dumbledore convert " "case-ns convert dumbledore"
527+
_completionTests_verifyCompletion "helm push-artifactory convert -s flag d" "dobby draco"
528+
_completionTests_verifyCompletion "helm push-artifactory convert " "hermione harry ron"
450529

451530
##############################################################
452531
# Completion with helm called through an alias or using a path

0 commit comments

Comments
 (0)