summaryrefslogtreecommitdiff
path: root/complete.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-23 07:45:28 +0300
committerGitHub <[email protected]>2017-05-23 07:45:28 +0300
commit3e6cff0740a53c8e9d6106ad29a4fd1bc4536c99 (patch)
tree4fd293605f8e917ba9848c39a10f37287d65ef2a /complete.go
parentbae3fd94da57ecb9d04524c0b34895df0f86a1d1 (diff)
parent17b9aed67cff5e3ed6032e82785d774eece5c7a1 (diff)
Merge pull request #37 from posener/fixes
Fixes
Diffstat (limited to 'complete.go')
-rw-r--r--complete.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/complete.go b/complete.go
index be0876e..1df6617 100644
--- a/complete.go
+++ b/complete.go
@@ -6,6 +6,7 @@
package complete
import (
+ "flag"
"fmt"
"os"
"strings"
@@ -36,11 +37,21 @@ func New(name string, command Command) *Complete {
}
}
-// Run get a command, get the typed arguments from environment
-// variable, and print out the complete options
+// Run runs the completion and add installation flags beforehand.
+// The flags are added to the main flag CommandLine variable.
+func (c *Complete) Run() bool {
+ c.AddFlags(nil)
+ flag.Parse()
+ return c.Complete()
+}
+
+// Complete a command from completion line in environment variable,
+// and print out the complete options.
// returns success if the completion ran or if the cli matched
// any of the given flags, false otherwise
-func (c *Complete) Run() bool {
+// For installation: it assumes that flags were added and parsed before
+// it was called.
+func (c *Complete) Complete() bool {
line, ok := getLine()
if !ok {
// make sure flags parsed,