package cli import ( "flag" "fmt" ) type CLIOptions struct { Input string Verbose bool } func ParseOptions(args []string) (*CLIOptions, error) { // Parse flags and arguments. verbose := flag.Bool("v", false, "Verbosity. If set, the program will print logs.") flag.Parse() if flag.NArg() == 0 { return nil, fmt.Errorf("No input given.") } else if flag.NArg() > 1 { return nil, fmt.Errorf("More than 1 command-line argument.") } return &CLIOptions{ Input: flag.Arg(0), Verbose: *verbose, }, nil }