-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output help message #23
Comments
Creating a new Helper interface + adding a new parameter to the current loaders will give the most extensibility. type EnvironmentLoader struct {
Prefix string
CamelCase bool
Usage func()
} Having Usage as a property will help with custom usage messages. Implementer can easily set usage function. If |
The problem is, loading is not context sensitive. All the loader knows, there is something that has the For example mitcellh/cli does have a help method just for it: https://godoc.org/github.com/mitchellh/cli#Command type Command interface {
// Help should return long-form help text that includes the command-line
// usage, a brief few sentences explaining the function of the command,
// and the complete list of flags the command accepts.
Help() string
// Run should run the actual command with the given CLI instance and
// command-line arguments. It should return the exit status when it is
// finished.
Run(args []string) int
// Synopsis should return a one-line, short synopsis of the command.
// This should be less than 50 characters ideally.
Synopsis() string
} Having |
I'm 👍 on changing the |
Hi guys. Im ok with changing the https://github.com/koding/multiconfig/blob/master/flag.go in private method contains the following snippet:
which then calls another private method
There is no way to nicely alter the documentation per flag My "solution" is to copy the entire file just to rewrite Any thoughts on a more general solution to this part. We could
This last one seems simplest and matches the existing system of setting values
and maybe about 5 LOC to impliment. I'm happy to do the work in any of them, but would love some direction on the approach you are most comfortable with. thanks for your time! nickg |
hi @fatih I'm sure you are busy but any thoughts on the above proposal to allow customization of |
@client9 Sorry I was on vacation. I think the best way is to provide a type T struct {
Port `flagUsage: "Port is used to specify the server port"`
} But this is not related with your |
@fatih no problem on delay. Vacation is good. I'm bouncing between a new projects on github, but I hope to get a pull request to you today for review. thanks! nickg update: 8 days later... ok take 2 on doing this. |
Part of #23 - allow flagloader to set optional function to set flag usage
Hello! its super weird how flexible this package is (thank you!!), but yet, we still can't customize help or add in our own Usage()/Help() functions (i.e. a Null loader that is only there to print a opening or closing statement). I'll be working on the type Loader interface {
Load(s interface{}) error
Help() string
} solution. let me know if thats a problem! Or if you are working on an alternate solution. regards, n |
Hello! Let's do the easy ones first:
Ok thats simple. FlagLoader isn't much harder
So adding the the tricky part is using the Help() interface. The current
and to use it, I changed my app from config := &Config{}
l := multiconfig.MultiLoader(configLoaders...)
err := l.Load(config) // <------ if -help was done, this called os.Exit(2) :-(
if err != nil {
return nil, err
} to config := &Config{}
l := multiconfig.MultiLoader(configLoaders...)
err := l.Load(config)
if err != nil {
if err != flag.ErrHelp { // <----- golang stdlib flag specific
return nil, err
}
// if we are here, we asked for help.
// and I can add a header, footer whatever.
fmt.Println(cliLoader.Help())
fmt.Println(envLoader.Help())
os.Exit(2)
} So to keep backwards compatibility I recommend, we add to https://golang.org/pkg/flag/#ErrorHandling with the default of "ExitOnError // Call os.Exit(2)." This keeps the current behavior, If it is set to "ContinueOnError ErrorHandling = iota // Return a descriptive error." Then it does the behavior listed in the diff. That should make everyone happy ? thoughts welcome! n |
Ok now that #43 was merged in I can make PR for better review. coming soon. n |
Hmmm, I failed in my git commit message. see pull request! |
Currently we only output the dynamically generated flags and environments if something goes wrong. There is no manual way of outputing the flags. For example if we only use the
env
loader, there is again no way to output the help message, because currently the help message is only defined inside theflag
load.There a two ways to do it.
#1. Create a new interface
We create a new interface which every loader
could
implement:If this is implemented via a loader, we'll have another function that will print those:
This is totally optional, but at least it would imense helpful as we could generate those dynamically, as we do for envs, flags, etc...
#2. Extend the
Loader
interfaceThis is will add a new method to the existing
Loader
interface:After that, if
loader.Load(s)
fails it will output the help messages automatically (because the loader has access to theHelp()
method now. Or we could manually invoke to output the help messages.Opinions ?
The text was updated successfully, but these errors were encountered: