summaryrefslogtreecommitdiff
path: root/command.go
diff options
context:
space:
mode:
Diffstat (limited to 'command.go')
-rw-r--r--command.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/command.go b/command.go
index 9614269..6de48e9 100644
--- a/command.go
+++ b/command.go
@@ -49,6 +49,14 @@ type Flags map[string]Predictor
// Predict completion of flags names according to command line arguments
func (f Flags) Predict(a Args) (prediction []string) {
for flag := range f {
+ // If the flag starts with a hyphen, we avoid emitting the prediction
+ // unless the last typed arg contains a hyphen as well.
+ flagHyphenStart := len(flag) != 0 && flag[0] == '-'
+ lastHyphenStart := len(a.Last) != 0 && a.Last[0] == '-'
+ if flagHyphenStart && !lastHyphenStart {
+ continue
+ }
+
if match.Prefix(flag, a.Last) {
prediction = append(prediction, flag)
}