Last active
January 3, 2024 19:35
-
-
Save Integralist/74f55c0587238536f24644715e0f3325 to your computer and use it in GitHub Desktop.
[Golang Long and Short Flags] #go #golang #flags
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
var myFlagType string | |
func init() { | |
const ( | |
flagValue = "default value is foo" | |
flagUsage = "this is my flag explanation" | |
) | |
flag.StringVar(&myFlagType, "foo", flagValue, flagUsage) | |
flag.StringVar(&myFlagType, "f", flagValue, flagUsage+" (shorthand)") | |
flag.Parse() | |
} | |
// this works by using an alternative flag syntax, which allows you to | |
// specify a 'variable' to assign the incoming flag value to. | |
// this is different to `flag.String` where the returned type is a pointer. | |
// | |
// in the above example we can see we specify --foo and -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment