diff options
| author | Jeff Carr <[email protected]> | 2025-10-26 10:30:18 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-26 10:30:18 -0500 |
| commit | 337add61d45b558fe11765342b7498a86d5834df (patch) | |
| tree | 5952cdd2d28323352a3cc79ae62aeb5acda183e9 /complete.go | |
| parent | d4ac45d164ab08b212382220e31f12c810e77265 (diff) | |
argv finally doesn't suckv0.0.32
Diffstat (limited to 'complete.go')
| -rw-r--r-- | complete.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/complete.go b/complete.go new file mode 100644 index 0000000..b7c7a47 --- /dev/null +++ b/complete.go @@ -0,0 +1,42 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "fmt" + "strings" + + "go.wit.com/dev/alexflint/arg" + "go.wit.com/lib/protobuf/argvpb" +) + +// sent via -ldflags +var VERSION string +var BUILDTIME string + +// used for shell auto completion +var APPNAME string = "mirrors" // todo: get this from $0 + +func (args) MustParse() error { + me.pp = arg.MustParse(&argv) + return nil +} + +// sends the strings to bash or zsh that will be your options +func (a args) DoAutoComplete() error { + if argvpb.PB.GetCmd() == "" { + matches := []string{"--dry-run", "--force", "incoming", "walk", "list", "everything", "verify", "newest", "--create", "--verbose", "release"} + fmt.Fprintf(argvpb.Stdout, " %s", strings.Join(matches, " ")) + return nil + } + var err error + if me.pp == nil { + me.pp, err = arg.ParseFlagsArgv(&argv) + if err != nil { + return err + } + } + err = me.pp.WriteHelpForAutocomplete(argvpb.PB.Partial, argvpb.PB.Real...) + return err +} |
