32 lines
685 B
Go
32 lines
685 B
Go
package cli
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
)
|
|
|
|
type CLIOptions struct {
|
|
Input string
|
|
Verbose bool
|
|
Explanation bool
|
|
}
|
|
|
|
func ParseOptions(args []string) (*CLIOptions, error) {
|
|
// Parse flags and arguments.
|
|
verbose := flag.Bool("v", false, "Verbosity. If set, the program will print logs.")
|
|
explanation := flag.Bool("x", false, "Explanation. Whether or not to show all reduction steps.")
|
|
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,
|
|
Explanation: *explanation,
|
|
}, nil
|
|
}
|