28 lines
464 B
Go
28 lines
464 B
Go
package cli
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log/slog"
|
|
"os"
|
|
)
|
|
|
|
type CLIOptions struct {
|
|
Input string
|
|
}
|
|
|
|
func ParseOptions(args []string) (*CLIOptions, error) {
|
|
slog.Info("Parsing CLI arguments.", "args", os.Args)
|
|
|
|
// Parse flags and arguments.
|
|
flag.Parse()
|
|
|
|
switch flag.NArg() {
|
|
case 0:
|
|
return nil, fmt.Errorf("No input given.")
|
|
case 1:
|
|
return &CLIOptions{Input: flag.Arg(0)}, nil
|
|
default:
|
|
return nil, fmt.Errorf("More than 1 command-line argument.")
|
|
}
|
|
} |