From f9ba2e9ac3bbf2856255afdf4aa155b2b093e408 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Mon, 12 Aug 2024 08:01:38 +0000 Subject: [PATCH] fixup --- command.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/command.go b/command.go index 76adab8..9d10dfe 100644 --- a/command.go +++ b/command.go @@ -296,10 +296,16 @@ func copyFlagSetWithout(fs *pflag.FlagSet, without string) *pflag.FlagSet { } func (inv *Invocation) CurWords() (prev string, cur string) { - if len(inv.Args) == 1 { + switch len(inv.Args) { + // All the shells we support will supply at least one argument (empty string), + // but we don't want to panic. + case 0: + cur = "" + prev = "" + case 1: cur = inv.Args[0] prev = "" - } else { + default: cur = inv.Args[len(inv.Args)-1] prev = inv.Args[len(inv.Args)-2] }