fix: manage write error during the display of the DNS help. (#923)

This commit is contained in:
Ludovic Fernandez 2019-07-10 19:34:10 +02:00 committed by GitHub
parent f7dcb6ff22
commit 79f6b35841
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 963 additions and 928 deletions

View file

@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"io"
"os"
"strings"
"text/tabwriter"
@ -27,22 +28,46 @@ func dnsHelp(ctx *cli.Context) error {
code := ctx.String("code")
if code == "" {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
ew := &errWriter{w: w}
fmt.Fprintln(w, `Credentials for DNS providers must be passed through environment variables.`)
fmt.Fprintln(w)
fmt.Fprintln(w, `To display the documentation for a DNS providers:`)
fmt.Fprintln(w)
fmt.Fprintln(w, "\t$ lego dnshelp -c code")
fmt.Fprintln(w)
fmt.Fprintln(w, "All DNS codes:")
fmt.Fprintf(w, "\t%s\n", allDNSCodes())
fmt.Fprintln(w)
fmt.Fprintln(w, "More information: https://go-acme.github.io/lego/dns")
ew.writeln(`Credentials for DNS providers must be passed through environment variables.`)
ew.writeln()
ew.writeln(`To display the documentation for a DNS providers:`)
ew.writeln()
ew.writeln("\t$ lego dnshelp -c code")
ew.writeln()
ew.writeln("All DNS codes:")
ew.writef("\t%s\n", allDNSCodes())
ew.writeln()
ew.writeln("More information: https://go-acme.github.io/lego/dns")
if ew.err != nil {
return ew.err
}
return w.Flush()
}
displayDNSHelp(strings.ToLower(code))
return nil
return displayDNSHelp(strings.ToLower(code))
}
type errWriter struct {
w io.Writer
err error
}
func (ew *errWriter) writeln(a ...interface{}) {
if ew.err != nil {
return
}
_, ew.err = fmt.Fprintln(ew.w, a...)
}
func (ew *errWriter) writef(format string, a ...interface{}) {
if ew.err != nil {
return
}
_, ew.err = fmt.Fprintf(ew.w, format, a...)
}