2020-12-13 13:19:10 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-12-13 16:33:44 +01:00
|
|
|
"os"
|
2020-12-14 17:20:27 +01:00
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
2020-12-13 13:19:10 +01:00
|
|
|
)
|
|
|
|
|
2020-12-17 12:27:44 +01:00
|
|
|
// appHelpTextTemplate is the text/template to customise the Help output.
|
2020-12-13 16:33:44 +01:00
|
|
|
// Uses text/template to render templates.
|
2020-12-17 12:27:44 +01:00
|
|
|
var appHelpTextTemplate = `{{ "NAME" | color "" "heading" }}:
|
2020-12-14 17:20:27 +01:00
|
|
|
{{ .Name | color "green" "bold" }} 🐶 {{.Description}}
|
|
|
|
|
|
|
|
{{ "USAGE" | color "" "heading" }}:
|
|
|
|
{{ .Name | color "green" "" }} [--] {{ "[query options]" | color "yellow" "" }} {{ "[arguments...]" | color "cyan" "" }}
|
|
|
|
|
|
|
|
{{ "VERSION" | color "" "heading" }}:
|
|
|
|
{{.Version | color "red" "" }} - {{.Date | color "red" ""}}
|
|
|
|
|
|
|
|
{{ "EXAMPLES" | color "" "heading" }}:
|
|
|
|
{{ .Name | color "green" "" }} {{ "mrkaran.dev" | color "cyan" "" }} Query a domain using defaults
|
|
|
|
{{ .Name | color "green" "" }} {{ "mrkaran.dev CNAME" | color "cyan" "" }} Looks up for a CNAME record
|
|
|
|
{{ .Name | color "green" "" }} {{ "mrkaran.dev MX @9.9.9.9" | color "cyan" "" }} Uses a custom DNS resolver
|
|
|
|
{{ .Name | color "green" "" }} {{"-q mrkaran.dev -t MX -n 1.1.1.1" | color "yellow" ""}} Using named arguments
|
|
|
|
|
|
|
|
{{ "Free Form Arguments" | color "" "heading" }}:
|
|
|
|
Supply hostnames, query types, classes without any flag. For eg:
|
|
|
|
{{ .Name | color "green" "" }} {{"mrkaran.dev A @1.1.1.1" | color "cyan" "" }}
|
2020-12-13 16:33:44 +01:00
|
|
|
|
2020-12-14 17:20:27 +01:00
|
|
|
{{ "Query Options" | color "" "heading" }}:
|
|
|
|
{{"-q, --query=HOSTNAME" | color "yellow" ""}} Hostname to query the DNS records for
|
|
|
|
{{"-t, --type=TYPE" | color "yellow" ""}} Type of the DNS Record (A, MX, NS etc)
|
|
|
|
{{"-n, --nameserver=ADDR" | color "yellow" ""}} Address of a specific nameserver to send queries to (9.9.9.9, 1.1.1.1 etc)
|
|
|
|
{{"-c, --class=CLASS" | color "yellow" ""}} Network class of the DNS record (IN, CH, HS etc)
|
2020-12-13 13:19:10 +01:00
|
|
|
|
2020-12-14 17:20:27 +01:00
|
|
|
{{ "Output Options" | color "" "heading" }}:
|
|
|
|
{{"-J, --json " | color "yellow" ""}} Format the output as JSON
|
|
|
|
{{"--color " | color "yellow" ""}} Defaults to true. Set --color=false to disable colored output
|
|
|
|
{{"--debug " | color "yellow" ""}} Enable debug logging
|
|
|
|
{{"--time" | color "yellow" ""}} Shows how long the response took from the server
|
2020-12-13 16:33:44 +01:00
|
|
|
`
|
2020-12-13 13:19:10 +01:00
|
|
|
|
2020-12-13 16:33:44 +01:00
|
|
|
func renderCustomHelp() {
|
|
|
|
helpTmplVars := map[string]string{
|
|
|
|
"Name": "doggo",
|
|
|
|
"Description": "DNS Client for Humans",
|
|
|
|
"Version": buildVersion,
|
|
|
|
"Date": buildDate,
|
|
|
|
}
|
2020-12-14 17:20:27 +01:00
|
|
|
tmpl, err := template.New("test").Funcs(template.FuncMap{
|
|
|
|
"color": func(clr string, format string, str string) string {
|
|
|
|
formatter := color.New()
|
|
|
|
switch c := clr; c {
|
|
|
|
case "yellow":
|
|
|
|
formatter = formatter.Add(color.FgYellow)
|
|
|
|
case "red":
|
|
|
|
formatter = formatter.Add(color.FgRed)
|
|
|
|
case "cyan":
|
|
|
|
formatter = formatter.Add(color.FgCyan)
|
|
|
|
case "green":
|
|
|
|
formatter = formatter.Add(color.FgGreen)
|
|
|
|
}
|
|
|
|
switch f := format; f {
|
|
|
|
case "bold":
|
|
|
|
formatter = formatter.Add(color.Bold)
|
|
|
|
case "underline":
|
|
|
|
formatter = formatter.Add(color.Underline)
|
|
|
|
case "heading":
|
|
|
|
formatter = formatter.Add(color.Bold)
|
|
|
|
formatter = formatter.Add(color.Underline)
|
|
|
|
}
|
|
|
|
return formatter.SprintFunc()(str)
|
|
|
|
},
|
2020-12-17 12:27:44 +01:00
|
|
|
}).Parse(appHelpTextTemplate)
|
2020-12-13 16:33:44 +01:00
|
|
|
if err != nil {
|
2020-12-17 12:27:44 +01:00
|
|
|
// should ideally never happen.
|
2020-12-13 16:33:44 +01:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
err = tmpl.Execute(os.Stdout, helpTmplVars)
|
|
|
|
if err != nil {
|
2020-12-17 12:27:44 +01:00
|
|
|
// should ideally never happen.
|
2020-12-13 16:33:44 +01:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
os.Exit(0)
|
2020-12-13 13:19:10 +01:00
|
|
|
}
|