2019-03-11 18:56:48 +02:00
|
|
|
package cmd
|
2015-06-08 02:36:07 +02:00
|
|
|
|
|
|
|
import (
|
2016-03-18 02:32:24 +02:00
|
|
|
"fmt"
|
2019-07-10 19:34:10 +02:00
|
|
|
"io"
|
2019-03-08 20:47:06 +02:00
|
|
|
"strings"
|
2016-03-18 02:32:24 +02:00
|
|
|
"text/tabwriter"
|
2015-06-08 02:36:07 +02:00
|
|
|
|
2022-02-13 13:28:51 +02:00
|
|
|
"github.com/urfave/cli/v2"
|
2015-06-08 02:36:07 +02:00
|
|
|
)
|
|
|
|
|
2024-09-20 19:47:50 +02:00
|
|
|
const flgCode = "code"
|
|
|
|
|
2022-02-13 13:28:51 +02:00
|
|
|
func createDNSHelp() *cli.Command {
|
|
|
|
return &cli.Command{
|
2018-12-06 23:50:17 +02:00
|
|
|
Name: "dnshelp",
|
2019-03-08 20:47:06 +02:00
|
|
|
Usage: "Shows additional help for the '--dns' global option",
|
2018-12-06 23:50:17 +02:00
|
|
|
Action: dnsHelp,
|
2019-03-08 20:47:06 +02:00
|
|
|
Flags: []cli.Flag{
|
2022-02-13 13:28:51 +02:00
|
|
|
&cli.StringFlag{
|
2024-09-20 19:47:50 +02:00
|
|
|
Name: flgCode,
|
2022-02-13 13:28:51 +02:00
|
|
|
Aliases: []string{"c"},
|
|
|
|
Usage: fmt.Sprintf("DNS code: %s", allDNSCodes()),
|
2019-03-08 20:47:06 +02:00
|
|
|
},
|
|
|
|
},
|
2016-05-14 17:11:26 +02:00
|
|
|
}
|
2015-06-08 02:36:07 +02:00
|
|
|
}
|
2016-03-18 02:32:24 +02:00
|
|
|
|
2019-03-08 20:47:06 +02:00
|
|
|
func dnsHelp(ctx *cli.Context) error {
|
2024-09-20 19:47:50 +02:00
|
|
|
code := ctx.String(flgCode)
|
2019-03-08 20:47:06 +02:00
|
|
|
if code == "" {
|
2023-01-08 15:53:15 +02:00
|
|
|
w := tabwriter.NewWriter(ctx.App.Writer, 0, 0, 2, ' ', 0)
|
2019-07-10 19:34:10 +02:00
|
|
|
ew := &errWriter{w: w}
|
2019-03-08 20:47:06 +02:00
|
|
|
|
2019-07-10 19:34:10 +02:00
|
|
|
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:`)
|
2019-07-10 19:34:10 +02:00
|
|
|
ew.writeln()
|
|
|
|
ew.writeln("\t$ lego dnshelp -c code")
|
|
|
|
ew.writeln()
|
2023-01-08 15:53:15 +02:00
|
|
|
ew.writeln("Supported DNS providers:")
|
2019-07-10 19:34:10 +02:00
|
|
|
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
|
|
|
|
}
|
2019-03-08 20:47:06 +02:00
|
|
|
|
|
|
|
return w.Flush()
|
|
|
|
}
|
2016-03-18 02:32:24 +02:00
|
|
|
|
2023-01-08 15:53:15 +02:00
|
|
|
return displayDNSHelp(ctx.App.Writer, strings.ToLower(code))
|
2019-07-10 19:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2016-05-12 19:52:59 +02:00
|
|
|
|
2019-07-10 19:34:10 +02:00
|
|
|
_, ew.err = fmt.Fprintf(ew.w, format, a...)
|
2016-03-18 02:32:24 +02:00
|
|
|
}
|