go - Golang flag library: Unable to override Usage function that prints out command line usage -
I am working on a simple command line tool and I found a slight decrease in the default usage message. I want to define my own and I feel that I am doing it right, I am referring.
I have commented on the code I have written, so the file containing the main function now looks like this:
Package main import ("flag" "FMT" "OS") func main () {// Custom Usage Function Setup Flags (flag. Comendeline) // Define Flag ... // Then Pars Flag Flag. Purse () / custom code that uses the flag value ...} function (f * flagset) {f.Usage = func () {fmt.Println ("foo bar")}} It seems that this should work, but it is not. When & lt; Binary & gt; -H I get the default usage message and my custom foo bar message that I defined in my custom function is using Go version 1.3.3 on OSX. I found it but it's for 1.45 cco.
What am I doing?
edit:
In fact your code It works by revising! What version of GO are you using? You may need to recreate your code again.
The decision of to use function to call flag.go is in the source file, unexported function Usage () ( It is from 1.4):
func (f * flagSet) usage () {if f.Usage == zero {if f == CommandLine {Usage ()} and {defaultUsage (f )}} Else {f.Usage ()}} indicates that if is not flagSet.Usage zero , it It will be said that if it has not been invited for you, then it is most likely that before you go to 1.4 version (which you had confirmed in your comment) Using the RAN.
But since you are using the default flag command line flagset, you can just type:
// "f.usage Note "flag.Usage" instead of a flag. Use = throw () {fmt.Println ("Foo bar"}}
Comments
Post a Comment