FEATURE: "check" subcommand should send to stdout (#1755)

Co-authored-by: Grant Slater <github@firefishy.com>
This commit is contained in:
Tom Limoncelli 2022-09-22 11:03:03 -04:00 committed by GitHub
parent c56002e835
commit b821f4914f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,21 +25,41 @@ var _ = cmd(catDebug, func() *cli.Command {
}
}())
// CheckArgs encapsulates the flags/arguments for the check command.
type CheckArgs struct {
GetDNSConfigArgs
}
var _ = cmd(catDebug, func() *cli.Command {
var args PrintIRArgs
var args CheckArgs
// This is the same as print-ir with the following changes:
// - output defaults to /dev/null.
// - no JSON is output
// - error messages are sent to stdout.
// - prints "No errors." if there were no errors.
return &cli.Command{
Name: "check",
Usage: "Check and validate dnsconfig.js. Do not access providers.",
Usage: "Check and validate dnsconfig.js. Output to stdout. Do not access providers.",
Action: func(c *cli.Context) error {
if args.Output == "" {
args.Output = os.DevNull
}
err := exit(PrintIR(args))
// Create a PrintIRArgs struct and copy our args to the
// appropriate fields.
var pargs PrintIRArgs
// Copy these verbatim:
pargs.JSFile = args.JSFile
pargs.JSONFile = args.JSONFile
pargs.DevMode = args.DevMode
pargs.Variable = args.Variable
// Force these settings:
pargs.Pretty = false
pargs.Output = os.DevNull
// "check" sends all errors to stdout, not stderr.
cli.ErrWriter = os.Stdout
log.SetOutput(os.Stdout)
err := exit(PrintIR(pargs))
if err == nil {
fmt.Fprintf(os.Stderr, "No errors.\n")
fmt.Fprintf(os.Stdout, "No errors.\n")
}
return err
},