diff options
| author | Jeff Carr <[email protected]> | 2025-10-19 05:44:42 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-19 05:44:42 -0500 | 
| commit | f730ed88ee48128da1d4f841fd43616621613f00 (patch) | |
| tree | a511cbe46e3a6ca13c240fc15a03baf90165f09a | |
| parent | 34015f3d4ee487efe329d0387458f609343c2f9f (diff) | |
new argv that somewhat works betterv0.2.87
| -rw-r--r-- | argv.custom.go | 50 | ||||
| -rw-r--r-- | argv.struct.go (renamed from argv.go) | 70 | ||||
| -rw-r--r-- | argv.template.go | 80 | ||||
| -rw-r--r-- | exit.go | 8 | ||||
| -rw-r--r-- | main.go | 6 | ||||
| -rw-r--r-- | structs.go | 9 | 
6 files changed, 141 insertions, 82 deletions
diff --git a/argv.custom.go b/argv.custom.go new file mode 100644 index 0000000..f49adcd --- /dev/null +++ b/argv.custom.go @@ -0,0 +1,50 @@ +package main + +import ( +	"os" + +	"go.wit.com/lib/protobuf/argvpb" +	"go.wit.com/log" +) + +// sent via -ldflags +var VERSION string +var BUILDTIME string + +var APPNAME string = "virtigo" + +func (a args) Description() string { +	return ` +	virtigo: control your cluster + +This maintains a master list of all your vm's (aka 'droplets') +in your homelab cloud.  You can import libvirt xml files.  +This app talks to your hypervisors via the virtigod daemon.  +` +} + +var INFO *log.LogFlag +var POLL *log.LogFlag +var WARN *log.LogFlag +var EVENT *log.LogFlag + +func init() { +	full := "go.wit.com/apps/virtigo" +	short := "virtigo" + +	INFO = log.NewFlag("INFO", false, full, short, "general virtigo") +	POLL = log.NewFlag("POLL", false, full, short, "virtigo polling") +	WARN = log.NewFlag("WARN", true, full, short, "bad things") +	EVENT = log.NewFlag("EVENT", true, full, short, "hypeprvisor/droplet events") +} + +// sends the strings to bash or zsh that will be your options +func (a args) SendCompletionStrings(pb *argvpb.Argv) { +	if pb.Cmd == "" { +		base := []string{"--version", "list", "droplet"} +		pb.SendStrings(base) +	} else { +		pb.SubCommand(pb.Goargs...) +	} +	os.Exit(0) +} @@ -1,18 +1,5 @@  package main -import ( -	"os" - -	"go.wit.com/lib/protobuf/argvpb" -	"go.wit.com/log" -) - -/* -	this parses the command line arguements - -	this enables command line options from other packages like 'gui' and 'log' -*/ -  var argv args  type args struct { @@ -50,60 +37,3 @@ type DropletCmd struct {  	Spice   *EmptyCmd `arg:"subcommand:spice"                 help:"open spiceconsole"`  	Name    string    `arg:"--name"                           help:"what droplet to start"`  } - -func (a args) Description() string { -	return ` -	virtigo: control your cluster - -This maintains a master list of all your vm's (aka 'droplets') -in your homelab cloud.  You can import libvirt xml files.  -This app talks to your hypervisors via the virtigod daemon.  -` -} - -var INFO *log.LogFlag -var POLL *log.LogFlag -var WARN *log.LogFlag -var EVENT *log.LogFlag - -func init() { -	full := "go.wit.com/apps/virtigo" -	short := "virtigo" - -	INFO = log.NewFlag("INFO", false, full, short, "general virtigo") -	POLL = log.NewFlag("POLL", false, full, short, "virtigo polling") -	WARN = log.NewFlag("WARN", true, full, short, "bad things") -	EVENT = log.NewFlag("EVENT", true, full, short, "hypeprvisor/droplet events") -} - -/* -	handles shell autocomplete -*/ - -func (args) Version() string { -	return argvpb.StandardVersion(ARGNAME, VERSION, BUILDTIME) -} - -func (args) Appname() string { -	return ARGNAME -} - -func (args) Buildtime() (string, string) { -	return BUILDTIME, VERSION -} - -func (args) ArgvGui() error { -	me.myGui = argvpb.Gui() // adds the GUI package argv support -	return nil -} - -// sends the strings to bash or zsh that will be your options -func (a args) SendCompletionStrings(pb *argvpb.Argv) { -	if pb.Cmd == "" { -		base := []string{"--version", "list", "droplet"} -		pb.SendStrings(base) -	} else { -		pb.SubCommand(pb.Goargs...) -	} -	os.Exit(0) -} diff --git a/argv.template.go b/argv.template.go new file mode 100644 index 0000000..e7a9948 --- /dev/null +++ b/argv.template.go @@ -0,0 +1,80 @@ +package main + +// these are stubbed in functions needed +// just copy this file from another working app for now +// you shouldn't need to change anything here +// TODO: clean this up in argv + +import ( +	"os" + +	"go.wit.com/dev/alexflint/arg" +	"go.wit.com/gui" +	"go.wit.com/lib/fhelp" +	"go.wit.com/log" +) + +func (args) InitArgv() (string, string, string) { +	return APPNAME, BUILDTIME, VERSION +} + +// this function will send the current argv PB to go-args for parsing +func (args) ParseFlags(flags []string) error { +	var err error +	if me.pp == nil { +		// log.Info("Parse Flags GOT flags:", flags) +		me.pp, err = arg.ParseFlags(flags, &argv) +		// panic("got to the app's ParseFlags()") +	} else { +		panic("me.pp was not nil") +	} +	return err +} + +// add this funcgion: this will print the help +func (args) WriteHelpForSubcommand(cmd string) error { +	me.pp.WriteHelpForSubcommand(os.Stderr, cmd) +	return nil +} + +// this will print the help for the subcmd +func (args) WriteHelpForAutocomplete(part string, subcmd ...string) error { +	return me.pp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, part, subcmd...) +} + +func (args) WriteHelpForAutocompleteDebug(part string, subcmd ...string) error { +	f, _ := os.OpenFile("/tmp/argv.junk", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) +	return me.pp.WriteHelpForAutocomplete(f, os.Stdout, part, subcmd...) +} + +// add this funcgion: this will print the help +func (args) WriteHelp() error { +	me.pp.WriteHelp(os.Stderr) +	return nil +} + +func (args) InitGui() error { +	// panic("got here") +	arg.Register(&gui.ArgvGui) +	// me.gui = gui.PreInit() +	me.myGui = fhelp.Gui() +	return nil +} + +func (args) Exit() { +	gui.UnloadToolkits() +	if me.argv.Verbose() { +		log.Info("argv.Exit() called", APPNAME+".Exit()") +	} +	// remove this from the template for your app (or make one for youself if you need it) +	// forgeExit() // custom forge shutdown function +} + +func (args) Help() string { +	return "got app help" +} + +func (args) MustParse() error { +	me.pp = arg.MustParse(&argv) +	return nil +} @@ -12,26 +12,26 @@ import (  func okExit(note string) {  	if note != "" { -		log.Info(ARGNAME, "exit:", note, "ok") +		log.Info(APPNAME, "exit:", note, "ok")  	}  	gui.StandardExit()  	os.Exit(0)  }  func badExit(err error) { -	log.Info(ARGNAME, "failed: ", err) +	log.Info(APPNAME, "failed: ", err)  	gui.StandardExit()  	os.Exit(-1)  }  func exit(note string, err error) {  	if note != "" { -		log.Info(ARGNAME, "exit:", note, "ok") +		log.Info(APPNAME, "exit:", note, "ok")  	}  	gui.StandardExit()  	if err == nil {  		os.Exit(0)  	} -	log.Info(ARGNAME, "failed: ", err) +	log.Info(APPNAME, "failed: ", err)  	os.Exit(-1)  } @@ -14,12 +14,6 @@ import (  	"go.wit.com/log"  ) -// sent via -ldflags -var VERSION string -var BUILDTIME string - -var ARGNAME string = "virtigo" -  //go:embed resources/*  var resources embed.FS @@ -4,9 +4,12 @@ import (  	"net/url"  	"time" +	"go.wit.com/dev/alexflint/arg"  	"go.wit.com/gui" +	"go.wit.com/lib/fhelp"  	"go.wit.com/lib/gadgets"  	"go.wit.com/lib/protobuf/argvpb" +	"go.wit.com/lib/protobuf/forgepb"  	"go.wit.com/lib/protobuf/virtpb"  ) @@ -24,8 +27,10 @@ func (b *virtigoT) Enable() {  // this app's variables  type virtigoT struct { -	argv                  *argvpb.Argv                   // shell autocomplete -	myGui                 *argvpb.GuiPrep                // the gui toolkit handle +	argv                  *argvpb.Argv                   // more experiments for bash handling +	pp                    *arg.Parser                    // for parsing the command line args.  Yay to alexf lint! +	myGui                 *fhelp.GuiPrep                 // for initializing the GUI toolkits +	forge                 *forgepb.Forge                 // your customized repo preferences and settings  	e                     *virtpb.Events                 // virt protobuf events  	hmap                  map[*virtpb.Hypervisor]*HyperT // map to the local struct  	names                 []string                       // ?  | 
