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

FEATURE: Add experimental --reportmax flag (#2719)

This commit is contained in:
Tom Limoncelli
2023-12-13 12:32:39 -05:00
committed by GitHub
parent 2e4aa7a4c8
commit 0b8bb1d1ba
3 changed files with 26 additions and 9 deletions

View File

@ -77,6 +77,15 @@ func (args *PreviewArgs) flags() []cli.Flag {
Destination: &args.Full, Destination: &args.Full,
Usage: `Add headings, providers names, notifications of no changes, etc`, Usage: `Add headings, providers names, notifications of no changes, etc`,
}) })
flags = append(flags, &cli.IntFlag{
Name: "reportmax",
Hidden: true,
Usage: `Limit the IGNORE/NO_PURGE report to this many lines (Expermental. Will change in the future.)`,
Action: func(ctx *cli.Context, max int) error {
printer.MaxReport = max
return nil
},
})
flags = append(flags, &cli.Int64Flag{ flags = append(flags, &cli.Int64Flag{
Name: "bindserial", Name: "bindserial",
Destination: &bindserial.ForcedValue, Destination: &bindserial.ForcedValue,

View File

@ -98,8 +98,6 @@ The actual implementation combines this all into one loop:
Append "foreign list" to "desired". Append "foreign list" to "desired".
*/ */
const maxReport = 5
// handsoff processes the IGNORE*()//NO_PURGE/ENSURE_ABSENT features. // handsoff processes the IGNORE*()//NO_PURGE/ENSURE_ABSENT features.
func handsoff( func handsoff(
domain string, domain string,
@ -116,14 +114,19 @@ func handsoff(
return nil, nil, err return nil, nil, err
} }
var punct = ":"
if printer.MaxReport == 0 {
punct = "."
}
// Process IGNORE*() and NO_PURGE features: // Process IGNORE*() and NO_PURGE features:
ignorable, foreign := processIgnoreAndNoPurge(domain, existing, desired, absences, unmanagedConfigs, noPurge) ignorable, foreign := processIgnoreAndNoPurge(domain, existing, desired, absences, unmanagedConfigs, noPurge)
if len(foreign) != 0 { if len(foreign) != 0 {
msgs = append(msgs, fmt.Sprintf("%d records not being deleted because of NO_PURGE:", len(foreign))) msgs = append(msgs, fmt.Sprintf("%d records not being deleted because of NO_PURGE%s", len(foreign), punct))
msgs = append(msgs, reportSkips(foreign, !printer.SkinnyReport)...) msgs = append(msgs, reportSkips(foreign, !printer.SkinnyReport)...)
} }
if len(ignorable) != 0 { if len(ignorable) != 0 {
msgs = append(msgs, fmt.Sprintf("%d records not being deleted because of IGNORE*():", len(ignorable))) msgs = append(msgs, fmt.Sprintf("%d records not being deleted because of IGNORE*()%s", len(ignorable), punct))
msgs = append(msgs, reportSkips(ignorable, !printer.SkinnyReport)...) msgs = append(msgs, reportSkips(ignorable, !printer.SkinnyReport)...)
} }
@ -146,21 +149,23 @@ func handsoff(
return desired, msgs, nil return desired, msgs, nil
} }
// reportSkips reports records being skipped, if !full only the first maxReport are output. // reportSkips reports records being skipped, if !full only the first
// printer.MaxReport are output.
func reportSkips(recs models.Records, full bool) []string { func reportSkips(recs models.Records, full bool) []string {
var msgs []string var msgs []string
shorten := (!full) && (len(recs) > maxReport) shorten := (!full) && (len(recs) > printer.MaxReport)
last := len(recs) last := len(recs)
if shorten { if shorten {
last = maxReport last = printer.MaxReport
} }
for _, r := range recs[:last] { for _, r := range recs[:last] {
msgs = append(msgs, fmt.Sprintf(" %s. %s %s", r.GetLabelFQDN(), r.Type, r.GetTargetCombined())) msgs = append(msgs, fmt.Sprintf(" %s. %s %s", r.GetLabelFQDN(), r.Type, r.GetTargetCombined()))
} }
if shorten { if shorten && printer.MaxReport != 0 {
msgs = append(msgs, fmt.Sprintf(" ...and %d more... (use --full to show all)", len(recs)-maxReport)) msgs = append(msgs, fmt.Sprintf(" ...and %d more... (use --full to show all)", len(recs)-printer.MaxReport))
} }
return msgs return msgs

View File

@ -72,6 +72,9 @@ var (
// variable name is easy to grep for when we make the conversion. // variable name is easy to grep for when we make the conversion.
var SkinnyReport = true var SkinnyReport = true
// MaxReport represents how many records to show if SkinnyReport == true
var MaxReport = 5
// 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