summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--complete.go18
-rw-r--r--parse.go10
2 files changed, 18 insertions, 10 deletions
diff --git a/complete.go b/complete.go
index 8cb062e..25d5ef6 100644
--- a/complete.go
+++ b/complete.go
@@ -41,21 +41,15 @@ func ParseFlagsArgv(dest ...interface{}) (*Parser, error) {
argvpb.SetDebug(true)
argvpb.PB.HelpCounter = 0
if argvpb.Len() == 0 {
- fmt.Fprintf(argvpb.Stddbg, "len(PB.Real)=(%d)\n", len(argvpb.PB.Real))
+ // user didn't enter any text and is hitting <tab> after the command itself
p.WriteHelp(argvpb.Stderr)
- fmt.Fprintf(argvpb.Stddbg, "WriteHelp() (%v)\n", "fricking got here")
- fmt.Fprintf(argvpb.Stddbg, "WriteHelp() (%v)\n", "fricking got here")
- fmt.Fprintf(argvpb.Stddbg, "WriteHelp() (%v)\n", "fricking got here")
return p, errors.New("WriteHelp() worked")
- } else {
- fmt.Fprintf(argvpb.Stddbg, "WriteHelp() damnit len(%v) (%v)\n", len(argvpb.PB.Real), argvpb.PB.Real)
- fmt.Fprintf(argvpb.Stddbg, "WriteHelp() damnit len(%v) (%v)\n", len(argvpb.PB.Real), argvpb.PB.Real)
- fmt.Fprintf(argvpb.Stddbg, "WriteHelp() damnit len(%v) (%v)\n", len(argvpb.PB.Real), argvpb.PB.Real)
}
+ // user is trying to get help for a subcommand
err = p.WriteHelpForAutocomplete("", argvpb.PB.Real...)
if err != nil {
- fmt.Fprintf(argvpb.Stddbg, "returned from WriteHelpForAutocomplete() pb.Real(%v)\n", argvpb.PB.Real)
- fmt.Fprintf(argvpb.Stddbg, "returned from WriteHelpForAutocomplete(%v)\n", err)
+ // fmt.Fprintf(argvpb.Stddbg, "returned from WriteHelpForAutocomplete() pb.Real(%v)\n", argvpb.PB.Real)
+ fmt.Fprintf(argvpb.Stddbg, "WriteHelpForAutocomplete() err(%v)\n", err)
}
return p, errors.New("WriteHelpForAutocomplete() worked")
}
@@ -63,6 +57,10 @@ func ParseFlagsArgv(dest ...interface{}) (*Parser, error) {
err = p.WriteHelpForAutocomplete(argvpb.PB.Partial, argvpb.PB.Real...)
fmt.Fprintf(argvpb.Stderr, "returned from WriteHelpForAutocomplete() pb.Real(%v)\n", argvpb.PB.Real)
fmt.Fprintf(argvpb.Stderr, "returned from WriteHelpForAutocomplete(%v)\n", err)
+ if p.match != nil {
+ // calls back to the application. this allows the application to provide autocomplete matches
+ p.match()
+ }
return p, errors.New("WriteHelpForAutocomplete() subcommand worked")
}
return p, nil
diff --git a/parse.go b/parse.go
index 4c47316..cc2161e 100644
--- a/parse.go
+++ b/parse.go
@@ -168,6 +168,7 @@ type Parser struct {
config Config
version string
description string
+ match func() bool
epilogue string
// the following field changes during processing of command line arguments
@@ -190,6 +191,12 @@ type Described interface {
Description() string
}
+// will let the application provide matches for autocomplete
+type Matched interface {
+ // the application should return true if it's happy with itself
+ Match() bool
+}
+
// Epilogued is the interface that the destination struct should implement to
// add an epilogue string at the bottom of the help message.
type Epilogued interface {
@@ -300,6 +307,9 @@ func NewParser(config Config, dests ...interface{}) (*Parser, error) {
if dest, ok := dest.(Described); ok {
p.description = dest.Description()
}
+ if dest, ok := dest.(Matched); ok {
+ p.match = dest.Match
+ }
if dest, ok := dest.(Epilogued); ok {
p.epilogue = dest.Epilogue()
}