summaryrefslogtreecommitdiff
path: root/run.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-06 18:55:54 +0300
committerEyal Posener <[email protected]>2017-05-06 18:55:54 +0300
commit4f47fe9246e715f11272d6323343a12797d4d13f (patch)
tree65eb8cd82bbb5da33c548b5510f91f8017b04330 /run.go
parentd33bac720bcaf13a5ee9f6f165293183d2e3e24d (diff)
Add easy way to install the bash completion
Diffstat (limited to 'run.go')
-rw-r--r--run.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/run.go b/run.go
index d0c9a57..bd9f662 100644
--- a/run.go
+++ b/run.go
@@ -14,7 +14,11 @@ const (
// Run get a command, get the typed arguments from environment
// variable, and print out the complete options
func Run(c Command) {
- args := getLine()
+ args, ok := getLine()
+ if !ok {
+ runCommandLine(c.Name)
+ return
+ }
Log("Completing args: %s", args)
options := complete(c, args)
@@ -38,12 +42,12 @@ func complete(c Command, args []string) (matching []string) {
return
}
-func getLine() []string {
+func getLine() ([]string, bool) {
line := os.Getenv(envComplete)
if line == "" {
- panic("should be run as a complete script")
+ return nil, false
}
- return strings.Split(line, " ")
+ return strings.Split(line, " "), true
}
func last(args []string) (last string) {