forked from TrueCloudLab/lego
fix: manage write error during the display of the DNS help. (#923)
This commit is contained in:
parent
f7dcb6ff22
commit
79f6b35841
3 changed files with 963 additions and 928 deletions
|
@ -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...)
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,8 +9,6 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/go-acme/lego/log"
|
||||
)
|
||||
|
||||
func allDNSCodes() string {
|
||||
|
@ -24,35 +22,42 @@ func allDNSCodes() string {
|
|||
return strings.Join(providers, ", ")
|
||||
}
|
||||
|
||||
func displayDNSHelp(name string) {
|
||||
func displayDNSHelp(name string) error {
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||
ew := &errWriter{w: w}
|
||||
|
||||
switch name {
|
||||
{{ range $provider := .Providers }}
|
||||
case "{{ $provider.Code }}":
|
||||
// generated from: {{ .GeneratedFrom }}
|
||||
fmt.Fprintln(w, `Configuration for {{ $provider.Name }}.`)
|
||||
fmt.Fprintln(w, `Code: '{{ $provider.Code }}'`)
|
||||
fmt.Fprintln(w, `Since: '{{ $provider.Since }}'`)
|
||||
fmt.Fprintln(w)
|
||||
ew.writeln(`Configuration for {{ $provider.Name }}.`)
|
||||
ew.writeln(`Code: '{{ $provider.Code }}'`)
|
||||
ew.writeln(`Since: '{{ $provider.Since }}'`)
|
||||
ew.writeln()
|
||||
{{if $provider.Configuration }}{{if $provider.Configuration.Credentials }}
|
||||
fmt.Fprintln(w, `Credentials:`)
|
||||
ew.writeln(`Credentials:`)
|
||||
{{- range $k, $v := $provider.Configuration.Credentials }}
|
||||
fmt.Fprintln(w,` - "{{ $k }}": {{ safe $v }}`)
|
||||
ew.writeln(` - "{{ $k }}": {{ safe $v }}`)
|
||||
{{- end}}
|
||||
fmt.Fprintln(w)
|
||||
ew.writeln()
|
||||
{{end}}{{if $provider.Configuration.Additional }}
|
||||
fmt.Fprintln(w, `Additional Configuration:`)
|
||||
ew.writeln(`Additional Configuration:`)
|
||||
{{- range $k, $v := $provider.Configuration.Additional }}
|
||||
fmt.Fprintln(w, ` - "{{ $k }}": {{ safe $v }}`)
|
||||
ew.writeln(` - "{{ $k }}": {{ safe $v }}`)
|
||||
{{- end}}
|
||||
{{end}}{{end}}
|
||||
fmt.Fprintln(w)
|
||||
fmt.Fprintln(w, `More information: https://go-acme.github.io/lego/dns/{{ $provider.Code }}`)
|
||||
ew.writeln()
|
||||
ew.writeln(`More information: https://go-acme.github.io/lego/dns/{{ $provider.Code }}`)
|
||||
{{end}}
|
||||
case "manual":
|
||||
fmt.Fprintln(w, `Solving the DNS-01 challenge using CLI prompt.`)
|
||||
ew.writeln(`Solving the DNS-01 challenge using CLI prompt.`)
|
||||
default:
|
||||
log.Fatalf("%q is not yet supported.", name)
|
||||
return fmt.Errorf("%q is not yet supported", name)
|
||||
}
|
||||
w.Flush()
|
||||
|
||||
if ew.err != nil {
|
||||
return fmt.Errorf("error: %v", ew.err)
|
||||
}
|
||||
|
||||
return w.Flush()
|
||||
}
|
Loading…
Reference in a new issue