mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
@@ -22,7 +22,7 @@ type CLI interface {
|
||||
PromptToRun() bool
|
||||
}
|
||||
|
||||
// Printer is a simple acstraction for printing data. Can be passed to providers to give simple output capabilities.
|
||||
// Printer is a simple abstraction for printing data. Can be passed to providers to give simple output capabilities.
|
||||
type Printer interface {
|
||||
Debugf(fmt string, args ...interface{})
|
||||
Warnf(fmt string, args ...interface{})
|
||||
@@ -30,16 +30,20 @@ type Printer interface {
|
||||
|
||||
var reader = bufio.NewReader(os.Stdin)
|
||||
|
||||
// ConsolePrinter is a handle for the console printer.
|
||||
type ConsolePrinter struct{}
|
||||
|
||||
// StartDomain is called at the start of each domain.
|
||||
func (c ConsolePrinter) StartDomain(domain string) {
|
||||
fmt.Printf("******************** Domain: %s\n", domain)
|
||||
}
|
||||
|
||||
// PrintCorrection is called to print/format each correction.
|
||||
func (c ConsolePrinter) PrintCorrection(i int, correction *models.Correction) {
|
||||
fmt.Printf("#%d: %s\n", i+1, correction.Msg)
|
||||
}
|
||||
|
||||
// PromptToRun prompts the user to see if they want to execute a correction.
|
||||
func (c ConsolePrinter) PromptToRun() bool {
|
||||
fmt.Print("Run? (Y/n): ")
|
||||
txt, err := reader.ReadString('\n')
|
||||
@@ -57,6 +61,7 @@ func (c ConsolePrinter) PromptToRun() bool {
|
||||
return run
|
||||
}
|
||||
|
||||
// EndCorrection is called at the end of each correction.
|
||||
func (c ConsolePrinter) EndCorrection(err error) {
|
||||
if err != nil {
|
||||
fmt.Println("FAILURE!", err)
|
||||
@@ -65,6 +70,7 @@ func (c ConsolePrinter) EndCorrection(err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// StartDNSProvider is called at the start of each new provider.
|
||||
func (c ConsolePrinter) StartDNSProvider(provider string, skip bool) {
|
||||
lbl := ""
|
||||
if skip {
|
||||
@@ -73,6 +79,7 @@ func (c ConsolePrinter) StartDNSProvider(provider string, skip bool) {
|
||||
fmt.Printf("----- DNS Provider: %s...%s", provider, lbl)
|
||||
}
|
||||
|
||||
// StartRegistrar is called at the start of each new registrar.
|
||||
func (c ConsolePrinter) StartRegistrar(provider string, skip bool) {
|
||||
lbl := ""
|
||||
if skip {
|
||||
@@ -81,6 +88,7 @@ func (c ConsolePrinter) StartRegistrar(provider string, skip bool) {
|
||||
fmt.Printf("----- Registrar: %s...%s", provider, lbl)
|
||||
}
|
||||
|
||||
// EndProvider is called at the end of each provider.
|
||||
func (c ConsolePrinter) EndProvider(numCorrections int, err error) {
|
||||
if err != nil {
|
||||
fmt.Println("ERROR")
|
||||
@@ -94,10 +102,12 @@ func (c ConsolePrinter) EndProvider(numCorrections int, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Debugf is called to print/format debug information.
|
||||
func (c ConsolePrinter) Debugf(format string, args ...interface{}) {
|
||||
fmt.Printf(format, args...)
|
||||
}
|
||||
|
||||
// Warnf is called to print/format a warning.
|
||||
func (c ConsolePrinter) Warnf(format string, args ...interface{}) {
|
||||
fmt.Printf("WARNING: "+format, args...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user