38 lines
911 B
Go
38 lines
911 B
Go
package cli
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
)
|
|
|
|
// Arguments given to program.
|
|
type Options struct {
|
|
// The source code given to the program.
|
|
Input string
|
|
// Whether or not to print debug logs.
|
|
Verbose bool
|
|
// Whether or not to print an explanation of the reduction.
|
|
Explanation bool
|
|
}
|
|
|
|
// Extract the program configuration from the command-line arguments.
|
|
func ParseOptions() (*Options, error) {
|
|
// Parse flags.
|
|
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()
|
|
|
|
// Parse non-flag arguments.
|
|
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 &Options{
|
|
Input: flag.Arg(0),
|
|
Verbose: *verbose,
|
|
Explanation: *explanation,
|
|
}, nil
|
|
}
|