Created
January 16, 2022 16:05
-
-
Save anjanashankar9/5e0d0e21a7c94be3451f2db627aa657f to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
"flag" | |
"fmt" | |
"os" | |
) | |
// Define the flag | |
var help = flag.Bool("help", false, "Show help") | |
var boolFlag = false | |
var stringFlag = "Hello There!" | |
var intFlag int | |
func main() { | |
// Bind the flag | |
flag.BoolVar(&boolFlag, "boolFlag", false, "A boolean flag") | |
flag.StringVar(&stringFlag, "stringFlag", "Hello There!", "A string flag") | |
flag.IntVar(&intFlag, "intFlag", 4, "An integer flag") | |
// Parse the flag | |
flag.Parse() | |
// Usage Demo | |
if *help { | |
flag.Usage() | |
os.Exit(0) | |
} | |
fmt.Println("Boolean Flag is ", boolFlag) | |
fmt.Println("String Flag is ", stringFlag) | |
fmt.Println("Int Flag is ", intFlag) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment