This is how you would pass variable FlagSet variables and print defaults.

#go #GoLang

func PrintHelp(cmds ...*flag.FlagSet) {
	fmt.Println("Available commands :")
	for _, cmd := range cmds {
		fmt.Printf("\t%s\n", cmd.Name())
	fmt.Println("====== * * * ======")

	for _, cmd := range cmds {
		fmt.Printf("%s\n", cmd.Name())
func ProcessArgs() string {
        var what string
        var speed string

	// start option set
	startCmd := flag.NewFlagSet("start", flag.ContinueOnError)
	startCmd.StringVar(&what, "w", "anything", "start some object")
	startCmd.StringVar(&speed, "s", "max", "speed at which to start something")

	// stop option set
	stopCmd := flag.NewFlagSet("stop", flag.ContinueOnError)
	stopCmd.StringVar(&what, "w", "anything", "stop some object")

	if len(os.Args) < 2 {
		PrintHelp(startCmd, stopCmd)

	strOption := strings.ToLower(os.Args[1])

	switch strOption {
	case startCmd.Name():

	case stopCmd.Name():

		PrintHelp(startCmd, stopCmd)

	return strOption

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s