~hristoast/openmw-validator

7fbe6e05c1264cdf650b9cc80a495b3800aaa8ed — Hristos N. Triantafillou 16 days ago f526688 0.7
It can be useful to exit nonzero when there's a problem
3 files changed, 21 insertions(+), 14 deletions(-)

M cli.go
M config.go
M main.go
M cli.go => cli.go +9 -7
@@ 9,19 9,21 @@ import (
// Parse CLI args, return a `runConfig`.
func parseArgs() *runConfig {
	c := &runConfig{
		cfg:       "",
		checkPath: "",
		help:      false,
		log:       "",
		noReplace: false,
		quiet:     false,
		stdout:    false,
		cfg:         "",
		checkPath:   "",
		exitNonZero: false,
		help:        false,
		log:         "",
		noReplace:   false,
		quiet:       false,
		stdout:      false,
	}
	cfgPath, logPath := defaultCfgAndLog()
	c.log = logPath

	s := flag.StringP("cfg", "c", cfgPath, "Path to an openmw.cfg file to validate")
	p := flag.StringP("check-path", "p", "", "Report on an individual path, showing what is overwritten")
	flag.BoolVarP(&c.exitNonZero, "exit-nonzero", "E", false, "Make the program exit non-zero if there's a problem")
	flag.BoolVarP(&c.help, "help", "h", false, "Show the usage information for this program")
	flag.BoolVarP(&c.noReplace, "no-replace", "", false, "Don't report when a data file is replaced by another")
	flag.BoolVarP(&c.quiet, "quiet", "q", false, "Only minimal logging output")

M config.go => config.go +8 -7
@@ 66,13 66,14 @@ func (g *gameConfig) registerReplacement(new *dataFile, old *dataFile) {

// Program run configuration.
type runConfig struct {
	cfg       string
	checkPath string
	help      bool
	log       string
	noReplace bool
	quiet     bool
	stdout    bool
	cfg         string
	checkPath   string
	exitNonZero bool
	help        bool
	log         string
	noReplace   bool
	quiet       bool
	stdout      bool
}

// Return a string representing the default location of the `openmw.cfg` file.

M main.go => main.go +4 -0
@@ 66,5 66,9 @@ func main() {
		if !runCfg.stdout {
			fmt.Printf("Validation completed, log written to: %s\n", runCfg.log)
		}

		if runCfg.exitNonZero {
			os.Exit(1)
		}
	}
}