How to Parse Command-Line Flags in Go

Cli
Parse command-line flags in Go using the standard `flag` package to define variables and call `flag.Parse()`.

Use the flag package to define variables, call flag.Parse(), and access the values directly.

package main

import (
	"flag"
	"fmt"
)

func main() {
	name := flag.String("name", "World", "A greeting name")
	count := flag.Int("count", 1, "Number of greetings")
	flag.Parse()

	for i := 0; i < *count; i++ {
		fmt.Printf("Hello, %s\n", *name)
	}
}

Run with go run main.go -name=Go -count=3.