mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-10 01:18:30 +08:00
FEATURE: "check" subcommand should send to stdout (#1755)
Co-authored-by: Grant Slater <github@firefishy.com>
This commit is contained in:
parent
c56002e835
commit
b821f4914f
1 changed files with 28 additions and 8 deletions
|
@ -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
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue