flag pacakge
-
The flag package is a built-in library designed to parse those strings
into actual variables with specific types. It handles the heavy lifting
of validation and formatting.
While in os.args, user has to validate and format the args by himself.
Features
-
Type Safety: Automatically converts inputs to int, bool, string, etc.
Default values: We can provide default values if the user doesn't provide the flag.
Help Menus: It automatically generates a -help screen based on your code.
Flexibility: It accepts various formats like -name=bob, -name bob, or --name bob.
Parse Command line arguments
|
Example Runs:
|