Created
September 1, 2015 15:33
-
-
Save eparis/5d0c25f605209cf2c1c0 to your computer and use it in GitHub Desktop.
Program testing user defined --help flag and contextual information in help text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "github.com/spf13/cobra" | |
| ) | |
| var _ = fmt.Print | |
| func main() { | |
| cmd := &cobra.Command{ | |
| Use: "cmd", | |
| Short: "cmd help", | |
| Run: func(_ *cobra.Command, _ []string) {}, | |
| } | |
| cmd.Flags().Bool("help", false, "help flag") | |
| cmd.SetHelpTemplate(`{{.Name }} is so cool and awesome | |
| `) | |
| subcmd := &cobra.Command{ | |
| Use: "subcmd", | |
| Short: "subcmd help", | |
| Run: func(_ *cobra.Command, _ []string) {}, | |
| } | |
| subcmd.Flags().BoolP("help", "s", false, "subcmd help flag") | |
| subcmd.SetHelpTemplate(`But {{.Short}} is how it should be | |
| `) | |
| cmd.AddCommand(subcmd) | |
| subcmd2 := &cobra.Command{ | |
| Use: "subcmd2", | |
| Short: "subcmd help", | |
| Run: func(_ *cobra.Command, _ []string) {}, | |
| } | |
| subcmd2.Flags().String("help", "help", "subcmd2 help flag") | |
| cmd.AddCommand(subcmd2) | |
| cmd.Execute() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment