Last active
December 29, 2020 07:51
-
-
Save madflojo/5a71e12e48758d6af09dc73a2754f924 to your computer and use it in GitHub Desktop.
Example of a command-line projects main() function.
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
// main runs the command-line parsing and validations. This function will also start the application logic execution. | |
func main() { | |
// Parse command-line arguments | |
var opts options | |
args, err := flags.ParseArgs(&opts, os.Args[1:]) | |
if err != nil { | |
os.Exit(1) | |
} | |
// Convert to internal config | |
cfg := config.New() | |
cfg.Verbose = opts.Verbose | |
// more taking command line options and putting them into a config struct. | |
if opts.Pass { | |
// ask the user for a password | |
} | |
// Run the App | |
err = app.Run(cfg) | |
if err != nil { | |
// do stuff | |
os.Exit(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment