1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-23 09:15:11 +02:00
lego/cmd/cmd_dnshelp.go

74 lines
1.4 KiB
Go
Raw Normal View History

2019-03-11 18:56:48 +02:00
package cmd
import (
"fmt"
"io"
"strings"
"text/tabwriter"
"github.com/urfave/cli/v2"
)
func createDNSHelp() *cli.Command {
return &cli.Command{
Name: "dnshelp",
Usage: "Shows additional help for the '--dns' global option",
Action: dnsHelp,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "code",
Aliases: []string{"c"},
Usage: fmt.Sprintf("DNS code: %s", allDNSCodes()),
},
},
2016-05-14 17:11:26 +02:00
}
}
func dnsHelp(ctx *cli.Context) error {
code := ctx.String("code")
if code == "" {
2023-01-08 15:53:15 +02:00
w := tabwriter.NewWriter(ctx.App.Writer, 0, 0, 2, ' ', 0)
ew := &errWriter{w: w}
ew.writeln(`Credentials for DNS providers must be passed through environment variables.`)
ew.writeln()
2023-01-08 15:53:15 +02:00
ew.writeln(`To display the documentation for a specific DNS provider, run:`)
ew.writeln()
ew.writeln("\t$ lego dnshelp -c code")
ew.writeln()
2023-01-08 15:53:15 +02:00
ew.writeln("Supported DNS providers:")
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()
}
2023-01-08 15:53:15 +02:00
return displayDNSHelp(ctx.App.Writer, 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...)
}