diff options
| author | Jeff Carr <[email protected]> | 2025-09-09 02:30:38 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-09 02:33:08 -0500 | 
| commit | 4827be1d2ab4a37fc45a31116df2f109e1a8390e (patch) | |
| tree | fc504474185f6acb277baa21c82c494f879b8d4d | |
| parent | f1c1ca950c0a2868dc7feb6f86a0b48254d95a94 (diff) | |
cleaner argv autocomplete
| -rw-r--r-- | argv.go | 32 | ||||
| -rw-r--r-- | main.go | 15 | 
2 files changed, 6 insertions, 41 deletions
@@ -25,8 +25,6 @@ type args struct {  	Daemon   bool      `arg:"--daemon"                             help:"run as a daemon"`  	Force    bool      `arg:"--force"                              help:"try to strong arm things"`  	Verbose  bool      `arg:"--verbose"                            help:"show more output"` -	Bash     bool      `arg:"--bash"                               help:"generate bash completion"` -	BashAuto []string  `arg:"--auto-complete"                      help:"todo: move this to go-arg"`  }  type EmptyCmd struct { @@ -40,37 +38,13 @@ func init() {  	arg.MustParse(&argv)  } -// prints help to STDERR // TODO: move everything below this to go-args -func (args) doBashHelp() { -	if len(argv.BashAuto) < 2 { -		fmt.Fprintf(os.Stderr, "something went wrong with the GO args autocomplete in %s\n", ARGNAME) -		return -	} -	if argv.BashAuto[1] != "''" { -		// if this is not blank, then the user has typed something -		return -	} -	if argv.BashAuto[0] != ARGNAME { -		fmt.Fprintln(os.Stderr, argv.BashAuto[0]) -		// if this is not the name of the command, the user already started doing something -		return -	} -	if argv.BashAuto[0] == ARGNAME { -		me.pp.WriteHelp(os.Stderr) -		return -	} -	fmt.Fprintln(os.Stderr, "") -	fmt.Fprintln(os.Stderr, "something went wrong with the GO args package") -	fmt.Fprintln(os.Stderr, "") -} - -func (args) doBashAuto() { +func (a args) DoAutoComplete(argv []string) {  	// argv.doBashHelp() -	switch argv.BashAuto[0] { +	switch argv[0] {  	case "merge":  		fmt.Println("--force")  	default: -		if argv.BashAuto[0] == ARGNAME { +		if argv[0] == ARGNAME {  			// list the subcommands here  			fmt.Println("list merge")  		} @@ -8,8 +8,7 @@ import (  	"time"  	"go.wit.com/dev/alexflint/arg" -	"go.wit.com/gui" -	"go.wit.com/lib/fhelp" +	"go.wit.com/lib/gui/prep"  	"go.wit.com/lib/protobuf/forgepb"  	"go.wit.com/log"  ) @@ -28,18 +27,10 @@ var LIBDIR string = "/var/lib/forged/" // need to deprecate this  func main() {  	me = new(mainType) -	gui.InitArg() +	prep.Bash(ARGNAME, argv.DoAutoComplete) // todo: this line should be:  prep.Bash(argv) +	me.myGui = prep.Gui()                   // prepares the GUI package for go-args  	me.pp = arg.MustParse(&argv) -	if argv.Bash { -		fhelp.DoBash(ARGNAME) -		os.Exit(0) -	} -	if len(argv.BashAuto) != 0 { -		argv.doBashAuto() -		os.Exit(0) -	} -  	if argv.Hostname != "" {  		HOSTNAME = argv.Hostname  	}  | 
