mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-09-20 06:46:19 +08:00
FEATURE: Add experimental --reportmax flag (#2719)
This commit is contained in:
parent
2e4aa7a4c8
commit
0b8bb1d1ba
|
@ -77,6 +77,15 @@ func (args *PreviewArgs) flags() []cli.Flag {
|
|||
Destination: &args.Full,
|
||||
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{
|
||||
Name: "bindserial",
|
||||
Destination: &bindserial.ForcedValue,
|
||||
|
|
|
@ -98,8 +98,6 @@ The actual implementation combines this all into one loop:
|
|||
Append "foreign list" to "desired".
|
||||
*/
|
||||
|
||||
const maxReport = 5
|
||||
|
||||
// handsoff processes the IGNORE*()//NO_PURGE/ENSURE_ABSENT features.
|
||||
func handsoff(
|
||||
domain string,
|
||||
|
@ -116,14 +114,19 @@ func handsoff(
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
var punct = ":"
|
||||
if printer.MaxReport == 0 {
|
||||
punct = "."
|
||||
}
|
||||
|
||||
// Process IGNORE*() and NO_PURGE features:
|
||||
ignorable, foreign := processIgnoreAndNoPurge(domain, existing, desired, absences, unmanagedConfigs, noPurge)
|
||||
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)...)
|
||||
}
|
||||
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)...)
|
||||
}
|
||||
|
||||
|
@ -146,21 +149,23 @@ func handsoff(
|
|||
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 {
|
||||
var msgs []string
|
||||
|
||||
shorten := (!full) && (len(recs) > maxReport)
|
||||
shorten := (!full) && (len(recs) > printer.MaxReport)
|
||||
|
||||
last := len(recs)
|
||||
if shorten {
|
||||
last = maxReport
|
||||
last = printer.MaxReport
|
||||
}
|
||||
|
||||
for _, r := range recs[:last] {
|
||||
msgs = append(msgs, fmt.Sprintf(" %s. %s %s", r.GetLabelFQDN(), r.Type, r.GetTargetCombined()))
|
||||
}
|
||||
if shorten {
|
||||
msgs = append(msgs, fmt.Sprintf(" ...and %d more... (use --full to show all)", len(recs)-maxReport))
|
||||
if shorten && printer.MaxReport != 0 {
|
||||
msgs = append(msgs, fmt.Sprintf(" ...and %d more... (use --full to show all)", len(recs)-printer.MaxReport))
|
||||
}
|
||||
|
||||
return msgs
|
||||
|
|
|
@ -72,6 +72,9 @@ var (
|
|||
// variable name is easy to grep for when we make the conversion.
|
||||
var SkinnyReport = true
|
||||
|
||||
// MaxReport represents how many records to show if SkinnyReport == true
|
||||
var MaxReport = 5
|
||||
|
||||
// ConsolePrinter is a handle for the console printer.
|
||||
type ConsolePrinter struct {
|
||||
Reader *bufio.Reader
|
||||
|
|
Loading…
Reference in a new issue