aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2019-11-28 19:24:35 +0000
committerChristine Dodrill <me@christine.website>2019-11-28 19:24:35 +0000
commitfaa5368bc50c84c3a1dfaf67bc21c2cd2bbb921f (patch)
tree8724fdbe33bc30504b09ccc3f4ded682de4c2f8b /internal
parenta24e7b68f0b4abd992b45536b2b3b7aab52e941a (diff)
downloadx-faa5368bc50c84c3a1dfaf67bc21c2cd2bbb921f.tar.xz
x-faa5368bc50c84c3a1dfaf67bc21c2cd2bbb921f.zip
completionv1.2.0
Diffstat (limited to 'internal')
-rw-r--r--internal/internal.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/internal.go b/internal/internal.go
index 1c78d60..e63f6f7 100644
--- a/internal/internal.go
+++ b/internal/internal.go
@@ -7,7 +7,9 @@ import (
"fmt"
"io/ioutil"
"os"
+ "path/filepath"
+ "github.com/posener/complete"
"go4.org/legal"
"within.website/confyg/flagconfyg"
"within.website/ln"
@@ -83,3 +85,23 @@ func HandleStartup() {
func init() {
http.DefaultTransport = useragent.Transport("within.website-x", "https://within.website/.x.botinfo", http.DefaultTransport)
}
+
+func HandleCompletion(args complete.Predictor, subcommands complete.Commands) {
+ cmd := complete.Command{
+ Flags: map[string]complete.Predictor{},
+ Sub: subcommands,
+ Args: args,
+ }
+
+ flag.CommandLine.VisitAll(func(fl *flag.Flag) {
+ cmd.Flags["-"+fl.Name] = complete.PredictAnything
+
+ if fl.DefValue == "true" || fl.DefValue == "false" {
+ cmd.Flags["-"+fl.Name] = complete.PredictNothing
+ }
+ })
+
+ if complete.New(filepath.Base(os.Args[0]), cmd).Run() {
+ os.Exit(0)
+ }
+}