Skip to content

Commit f9ba2e9

Browse files
committed
fixup
1 parent 20f9762 commit f9ba2e9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

command.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,16 @@ func copyFlagSetWithout(fs *pflag.FlagSet, without string) *pflag.FlagSet {
296296
}
297297

298298
func (inv *Invocation) CurWords() (prev string, cur string) {
299-
if len(inv.Args) == 1 {
299+
switch len(inv.Args) {
300+
// All the shells we support will supply at least one argument (empty string),
301+
// but we don't want to panic.
302+
case 0:
303+
cur = ""
304+
prev = ""
305+
case 1:
300306
cur = inv.Args[0]
301307
prev = ""
302-
} else {
308+
default:
303309
cur = inv.Args[len(inv.Args)-1]
304310
prev = inv.Args[len(inv.Args)-2]
305311
}

0 commit comments

Comments
 (0)