summaryrefslogtreecommitdiff
path: root/args.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2019-10-23 22:46:40 +0300
committerEyal Posener <[email protected]>2019-10-23 22:49:48 +0300
commitf7264fe38585e1c6efe68ea27bc27747fc21cf84 (patch)
treef2a8af9bf26cb8fca022da1246268969adc2d7ef /args.go
parente24ae2ec882eef4b8d9f42177fd026d3db4bdb73 (diff)
fix off-by-one error for sub command completion.
Fixes #97
Diffstat (limited to 'args.go')
-rw-r--r--args.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/args.go b/args.go
index 16e5ab3..3340285 100644
--- a/args.go
+++ b/args.go
@@ -85,16 +85,17 @@ func splitLastEqual(line []string) []string {
return append(line[:len(line)-1], parts...)
}
+// from returns a copy of Args of all arguments after the i'th argument.
func (a Args) from(i int) Args {
- if i > len(a.All) {
- i = len(a.All)
+ if i >= len(a.All) {
+ i = len(a.All) - 1
}
- a.All = a.All[i:]
+ a.All = a.All[i+1:]
- if i > len(a.Completed) {
- i = len(a.Completed)
+ if i >= len(a.Completed) {
+ i = len(a.Completed) - 1
}
- a.Completed = a.Completed[i:]
+ a.Completed = a.Completed[i+1:]
return a
}