2019-03-11 16:56:48 +00:00
|
|
|
package cmd
|
2015-06-08 00:36:07 +00:00
|
|
|
|
|
|
|
import (
|
2016-03-18 00:32:24 +00:00
|
|
|
"fmt"
|
2019-07-10 17:34:10 +00:00
|
|
|
"io"
|
2015-06-08 00:36:07 +00:00
|
|
|
"os"
|
2019-03-08 18:47:06 +00:00
|
|
|
"strings"
|
2016-03-18 00:32:24 +00:00
|
|
|
"text/tabwriter"
|
2015-06-08 00:36:07 +00:00
|
|
|
|
2016-07-13 19:03:47 +00:00
|
|
|
"github.com/urfave/cli"
|
2015-06-08 00:36:07 +00:00
|
|
|
)
|
|
|
|
|
2018-12-06 21:50:17 +00:00
|
|
|
func createDNSHelp() cli.Command {
|
|
|
|
return cli.Command{
|
|
|
|
Name: "dnshelp",
|
2019-03-08 18:47:06 +00:00
|
|
|
Usage: "Shows additional help for the '--dns' global option",
|
2018-12-06 21:50:17 +00:00
|
|
|
Action: dnsHelp,
|
2019-03-08 18:47:06 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "code, c",
|
|
|
|
Usage: fmt.Sprintf("DNS code: %s", allDNSCodes()),
|
|
|
|
},
|
|
|
|
},
|
2016-05-14 15:11:26 +00:00
|
|
|
}
|
2015-06-08 00:36:07 +00:00
|
|
|
}
|
2016-03-18 00:32:24 +00:00
|
|
|
|
2019-03-08 18:47:06 +00:00
|
|
|
func dnsHelp(ctx *cli.Context) error {
|
|
|
|
code := ctx.String("code")
|
|
|
|
if code == "" {
|
2019-05-27 17:20:45 +00:00
|
|
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
2019-07-10 17:34:10 +00:00
|
|
|
ew := &errWriter{w: w}
|
2019-03-08 18:47:06 +00:00
|
|
|
|
2019-07-10 17:34:10 +00:00
|
|
|
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
|
|
|
|
}
|
2019-03-08 18:47:06 +00:00
|
|
|
|
|
|
|
return w.Flush()
|
|
|
|
}
|
2016-03-18 00:32:24 +00:00
|
|
|
|
2019-07-10 17:34:10 +00:00
|
|
|
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
|
|
|
|
}
|
2016-05-12 17:52:59 +00:00
|
|
|
|
2019-07-10 17:34:10 +00:00
|
|
|
_, ew.err = fmt.Fprintf(ew.w, format, a...)
|
2016-03-18 00:32:24 +00:00
|
|
|
}
|