diff options
| author | Jeff Carr <[email protected]> | 2025-10-18 08:00:52 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-18 08:00:52 -0500 |
| commit | f683e1adc9fd612a67f6cc34ba3188a8120f87d7 (patch) | |
| tree | 925f08631f9ecb192adb8fdc2863612b68c3f1a6 | |
| parent | b2c353f48082a1d581bee0b6ee71c93f58bff603 (diff) | |
still tinkering
| -rw-r--r-- | argv.SendStrings.go | 6 | ||||
| -rw-r--r-- | argv.proto | 7 | ||||
| -rw-r--r-- | interface.go | 32 | ||||
| -rw-r--r-- | structs.go | 39 |
4 files changed, 57 insertions, 27 deletions
diff --git a/argv.SendStrings.go b/argv.SendStrings.go index 367de07..0351286 100644 --- a/argv.SendStrings.go +++ b/argv.SendStrings.go @@ -58,14 +58,16 @@ func (pb *Argv) SubCommand(cmd ...string) { // log.Fprintf(os.Stderr, "\n") } // last working line: me.writeHelpForAutocomplete(os.Stderr, os.Stdout, partial, cmd...) - me.writeHelpForAutocomplete() + partial := strings.Trim(pb.Partial, "'") + me.writeHelpForAutocompleteDebugFunc(partial, cmd...) // me.pp.GetUsageForSubcommand(os.Stdout, os.Stderr, partial, cmd) // me.pp.GetUsageForSubcommand(os.Stdout, nil, partial, cmd) } else { // last working: f, _ := os.OpenFile("/tmp/outlook", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) // last working: me.writeHelpForAutocomplete(f, os.Stdout, partial, cmd...) - me.writeHelpForAutocomplete() + partial := strings.Trim(pb.Partial, "'") + me.writeHelpForAutocompleteFunc(partial, cmd...) } os.Exit(0) } @@ -7,6 +7,12 @@ package argvpb; import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp import "google/protobuf/duration.proto"; // for duration +message App { + string APPNAME = 1; + string VERSION = 2; + string BUILDTIME = 3; +} + message Argv { // `autogenpb:marshal` `autogenpb:sort` `autogenpb:nomutex` google.protobuf.Timestamp ctime = 1; // when the user tried this autocomplete google.protobuf.Duration duration = 2; // time since the last autocomplete @@ -25,6 +31,7 @@ message Argv { // `autogenpb:marshal` ` repeated string goargs = 15; // what to send to alex flint's go-args for help bool fast = 16; // was the user fast last time? string fastcmd = 17; // what subcommand was the user fast on? + App app = 18; } message Argvs { // `autogenpb:marshal` `autogenpb:sort` `autogenpb:nomutex` diff --git a/interface.go b/interface.go index 13b2e71..a303515 100644 --- a/interface.go +++ b/interface.go @@ -5,24 +5,23 @@ import "go.wit.com/log" // this is a work in progress // WORKING ON START + type initArgvI interface { - // Version returns the version string that will be printed on a line by itself - // at the top of the help message. InitArgv() (string, string, string) } type mustParseI interface { - // Version returns the version string that will be printed on a line by itself - // at the top of the help message. MustParse() error } type parseFlagsI interface { - // Version returns the version string that will be printed on a line by itself - // at the top of the help message. ParseFlags([]string) error } +type writeHelpForAutocompleteI interface { + WriteHelpForAutocomplete(string, ...string) error +} + type initGuiI interface { // Version returns the version string that will be printed on a line by itself // at the top of the help message. @@ -87,6 +86,12 @@ func findAppInfo(tmp interface{}) { panic("you must define in your app the function: func (args) MustParse() error") } + if tmp, ok := tmp.(writeHelpForAutocompleteI); ok { + me.writeHelpForAutocompleteFunc = tmp.WriteHelpForAutocomplete + } else { + helpWriteHelpForAutocomplete() + } + if tmp, ok := tmp.(parseFlagsI); ok { me.parseFlagsFunc = tmp.ParseFlags } else { @@ -139,6 +144,21 @@ func findAppInfo(tmp interface{}) { } } +// func (p *Parser) WriteHelpForAutocomplete(stderr io.Writer, stdout io.Writer, partial string, subcommand ...string) error { +// me.pp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, partial, cmd...) +func helpWriteHelpForAutocomplete() { + log.Info("") + log.Info("// this will print the help for the subcmd") + log.Info("func (args) WriteHelpForAutocomplete(part string, subcmd ...string) error {") + log.Info(" return argvpp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, part, subcmd...)") + log.Info("}") + log.Info("") + log.Info("Just copy the argv.template.go file from forge") + log.Info("") + + panic("you must define this function in your application code") +} + func parseFlagsHelp() { log.Info("") log.Info("// this function will send the current argv PB to go-args for parsing") @@ -5,25 +5,26 @@ var me *AutoArgs // this is a work in progress type AutoArgs struct { - pb *Argv // the protobuf for the current process - id int // should be unique - Argv func([]string) // the function for shell autocomplete - initArgv func() (string, string, string) // this is required. gets APPNAME, BUILDTIME & VERSION - initGuiFunc func() error // this is required for 'gui' args to work - mustParseFunc func() error // calls go-arg.MustParse() - parseFlagsFunc func([]string) error // notsure yet - writeHelp func() // notsure yet - writeHelpForSubcommand func(string) // notsure yet - writeHelpForAutocomplete func() // notsure yet - examples func() string // some examples - appExit func() // app Exit() - buildtime func() (string, string) // some examples - autoFunc func(*Argv) // also a function for autocomplete - guiFunc func() error // enables Gui functions - ARGNAME string // a good way to track the name of the binary ? - VERSION string - BUILDTIME string - err error // store any errors from argv + pb *Argv // the protobuf for the current process + id int // should be unique + Argv func([]string) // the function for shell autocomplete + initArgv func() (string, string, string) // this is required. gets APPNAME, BUILDTIME & VERSION + initGuiFunc func() error // this is required for 'gui' args to work + mustParseFunc func() error // calls go-arg.MustParse() + parseFlagsFunc func([]string) error // calls go-arg.ParseFlags(flags) + writeHelpForAutocompleteFunc func(string, ...string) error // notsure yet + writeHelpForAutocompleteDebugFunc func(string, ...string) error // notsure yet + writeHelp func() // notsure yet + writeHelpForSubcommand func(string) // notsure yet + examples func() string // some examples + appExit func() // app Exit() + buildtime func() (string, string) // some examples + autoFunc func(*Argv) // also a function for autocomplete + guiFunc func() error // enables Gui functions + ARGNAME string // a good way to track the name of the binary ? + VERSION string + BUILDTIME string + err error // store any errors from argv // hidden bool // don't update the toolkits when it's hidden // pp *arg.Parser // for parsing the command line args. Yay to alexf lint! } |
