1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Add --verbose flag, default to less verbose output (#1721)

This commit is contained in:
Tom Limoncelli
2022-08-20 20:59:02 -04:00
committed by GitHub
parent d907cdd2c2
commit 8bb63be8f5
7 changed files with 35 additions and 6 deletions

View File

@@ -37,6 +37,7 @@ type PreviewArgs struct {
Notify bool Notify bool
WarnChanges bool WarnChanges bool
NoPopulate bool NoPopulate bool
Full bool
} }
func (args *PreviewArgs) flags() []cli.Flag { func (args *PreviewArgs) flags() []cli.Flag {
@@ -58,6 +59,11 @@ func (args *PreviewArgs) flags() []cli.Flag {
Destination: &args.NoPopulate, Destination: &args.NoPopulate,
Usage: `Use this flag to not auto-create non-existing zones at the provider`, Usage: `Use this flag to not auto-create non-existing zones at the provider`,
}) })
flags = append(flags, &cli.BoolFlag{
Name: "full",
Destination: &args.Full,
Usage: `Add headings, providers names, notifications of no changes, etc`,
})
return flags return flags
} }
@@ -102,6 +108,10 @@ func Push(args PushArgs) error {
// run is the main routine common to preview/push // run is the main routine common to preview/push
func run(args PreviewArgs, push bool, interactive bool, out printer.CLI) error { func run(args PreviewArgs, push bool, interactive bool, out printer.CLI) error {
// TODO: make truly CLI independent. Perhaps return results on a channel as they occur // TODO: make truly CLI independent. Perhaps return results on a channel as they occur
// This is a hack until we have the new printer replacement.
printer.SkinnyReport = !args.Full
cfg, err := GetDNSConfig(args.GetDNSConfigArgs) cfg, err := GetDNSConfig(args.GetDNSConfigArgs)
if err != nil { if err != nil {
return err return err

View File

@@ -57,7 +57,7 @@ D_EXTEND("sub.domain.tld",
); );
``` ```
This will end up in the following modifications: This will end up in the following modifications: (This output assumes the `--verbose` flag)
```text ```text
******************** Domain: domain.tld ******************** Domain: domain.tld

View File

@@ -21,7 +21,8 @@ for(i = 0; i < domains.length; i++) {
} }
``` ```
This will end up in following modifications: This will end up in following modifications: (All output assumes the `--verbose` flag)
```text ```text
******************** Domain: domain1.tld ******************** Domain: domain1.tld

View File

@@ -140,7 +140,8 @@ This code may not function properly if a domain has R53 as a Registrar
but not as a DnsProvider. The situation is described in but not as a DnsProvider. The situation is described in
[PR#155](https://github.com/StackExchange/dnscontrol/pull/155). [PR#155](https://github.com/StackExchange/dnscontrol/pull/155).
In this situation you will see a message like: In this situation you will see a message like: (This output assumes the `--verbose` flag)
```text ```text
----- Registrar: r53_main ----- Registrar: r53_main

View File

@@ -172,6 +172,8 @@ what changes need to be made and never makes any actual changes.
It will use APIs if needed to find out what DNS entries currently It will use APIs if needed to find out what DNS entries currently
exist. exist.
(All output assumes the `--verbose` flag)
It should look something like this: It should look something like this:
```text ```text

View File

@@ -7,6 +7,7 @@ import (
"strings" "strings"
"github.com/StackExchange/dnscontrol/v3/models" "github.com/StackExchange/dnscontrol/v3/models"
"github.com/StackExchange/dnscontrol/v3/pkg/printer"
) )
// DetermineNameservers will find all nameservers we should use for a domain. It follows the following rules: // DetermineNameservers will find all nameservers we should use for a domain. It follows the following rules:
@@ -25,7 +26,9 @@ func DetermineNameserversForProviders(dc *models.DomainConfig, providers []*mode
if n == 0 { if n == 0 {
continue continue
} }
if !printer.SkinnyReport {
fmt.Printf("----- Getting nameservers from: %s\n", dnsProvider.Name) fmt.Printf("----- Getting nameservers from: %s\n", dnsProvider.Name)
}
nss, err := dnsProvider.Driver.GetNameservers(dc.Name) nss, err := dnsProvider.Driver.GetNameservers(dc.Name)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -66,6 +66,11 @@ var (
} }
) )
// SkinnyReport is true to to disable certain print statements.
// This is a hack until we have the new printer replacement. The long
// variable name is easy to grep for when we make the conversion.
var SkinnyReport = true
// ConsolePrinter is a handle for the console printer. // ConsolePrinter is a handle for the console printer.
type ConsolePrinter struct { type ConsolePrinter struct {
Reader *bufio.Reader Reader *bufio.Reader
@@ -117,7 +122,9 @@ func (c ConsolePrinter) StartDNSProvider(provider string, skip bool) {
if skip { if skip {
lbl = " (skipping)\n" lbl = " (skipping)\n"
} }
if !SkinnyReport {
fmt.Fprintf(c.Writer, "----- DNS Provider: %s...%s\n", provider, lbl) fmt.Fprintf(c.Writer, "----- DNS Provider: %s...%s\n", provider, lbl)
}
} }
// StartRegistrar is called at the start of each new registrar. // StartRegistrar is called at the start of each new registrar.
@@ -126,7 +133,9 @@ func (c ConsolePrinter) StartRegistrar(provider string, skip bool) {
if skip { if skip {
lbl = " (skipping)\n" lbl = " (skipping)\n"
} }
if !SkinnyReport {
fmt.Fprintf(c.Writer, "----- Registrar: %s...%s\n", provider, lbl) fmt.Fprintf(c.Writer, "----- Registrar: %s...%s\n", provider, lbl)
}
} }
// EndProvider is called at the end of each provider. // EndProvider is called at the end of each provider.
@@ -139,6 +148,9 @@ func (c ConsolePrinter) EndProvider(numCorrections int, err error) {
if numCorrections == 1 { if numCorrections == 1 {
plural = "" plural = ""
} }
if (SkinnyReport) && (numCorrections == 0) {
return
}
fmt.Fprintf(c.Writer, "%d correction%s\n", numCorrections, plural) fmt.Fprintf(c.Writer, "%d correction%s\n", numCorrections, plural)
} }
} }