feat: Add help text
parent
61e92a7ccc
commit
80d43011f8
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
_Command-line DNS client written in Golang_
|
_Command-line DNS client written in Golang_
|
||||||
|
|
||||||
# WIP
|
![](www/static/main.png)
|
||||||
|
|
||||||
|
|
26
TODO.md
26
TODO.md
|
@ -10,8 +10,6 @@
|
||||||
- [x] Add DOH support
|
- [x] Add DOH support
|
||||||
- [x] Add DOT support
|
- [x] Add DOT support
|
||||||
- [x] Add DNS protocol on TCP mode support.
|
- [x] Add DNS protocol on TCP mode support.
|
||||||
- [ ] Error on NXDomain (Realted upstream [bug](https://github.com/miekg/dns/issues/1198))
|
|
||||||
- [ ] Support all DNS records?
|
|
||||||
- [x] Major records supported
|
- [x] Major records supported
|
||||||
|
|
||||||
## CLI Features
|
## CLI Features
|
||||||
|
@ -27,18 +25,27 @@
|
||||||
- [x] Neatly package them to load args in different functions
|
- [x] Neatly package them to load args in different functions
|
||||||
- [x] Upper case is not mandatory for query type/classes
|
- [x] Upper case is not mandatory for query type/classes
|
||||||
- [x] Output
|
- [x] Output
|
||||||
- [ ] Custom Help Text
|
- [x] Custom Help Text
|
||||||
- [x] Add examples
|
- [x] Add examples
|
||||||
- [ ] Colorize
|
- [x] Colorize
|
||||||
- [ ] Add different commands
|
- [x] Add different commands
|
||||||
- [x] Add client transport options
|
- [x] Add client transport options
|
||||||
- [x] Fix an issue while loading free form args, where the same records are being added twice
|
- [x] Fix an issue while loading free form args, where the same records are being added twice
|
||||||
- [x] Remove urfave/cli in favour of `pflag + koanf`
|
- [x] Remove urfave/cli in favour of `pflag + koanf`
|
||||||
|
|
||||||
|
## Refactors
|
||||||
|
|
||||||
|
- [ ] Don't abuse Hub as global. Refactor methods to be independent of hub.
|
||||||
|
- [ ] Add meaningful comments where required.
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
- [ ] Add tests for Command Line Usage.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
- [ ] README
|
||||||
|
- [ ] Usage
|
||||||
|
- [ ] Installation
|
||||||
|
- [ ] Features
|
||||||
- [ ] Mkdocs init project
|
- [ ] Mkdocs init project
|
||||||
- [ ] Custom Index (Landing Page)
|
- [ ] Custom Index (Landing Page)
|
||||||
|
|
||||||
|
@ -47,9 +54,10 @@
|
||||||
- [ ] Snap
|
- [ ] Snap
|
||||||
- [ ] Homebrew
|
- [ ] Homebrew
|
||||||
- [ ] ARM
|
- [ ] ARM
|
||||||
|
- [ ] Docker
|
||||||
|
## Future Release
|
||||||
## v1.0
|
|
||||||
|
|
||||||
- [ ] Support obscure protocal tweaks in `dig`
|
- [ ] Support obscure protocal tweaks in `dig`
|
||||||
- [ ] `digfile`
|
- [ ] `digfile`
|
||||||
|
- [ ] Support more DNS Record Types
|
||||||
|
- [ ] Error on NXDomain (Realted upstream [bug](https://github.com/miekg/dns/issues/1198))
|
||||||
|
|
74
cmd/help.go
74
cmd/help.go
|
@ -1,26 +1,50 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
|
||||||
"os"
|
"os"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AppHelpTemplate is the text template to customise the Help output.
|
// AppHelpTemplate is the text template to customise the Help output.
|
||||||
// Uses text/template to render templates.
|
// Uses text/template to render templates.
|
||||||
var AppHelpTemplate = `NAME:
|
var AppHelpTemplate = `{{ "NAME" | color "" "heading" }}:
|
||||||
🐶 {{.Name}} - {{.Description}}
|
{{ .Name | color "green" "bold" }} 🐶 {{.Description}}
|
||||||
|
|
||||||
USAGE:
|
{{ "USAGE" | color "" "heading" }}:
|
||||||
{{.Name}} [OPTIONS] [--] <arguments>
|
{{ .Name | color "green" "" }} [--] {{ "[query options]" | color "yellow" "" }} {{ "[arguments...]" | color "cyan" "" }}
|
||||||
|
|
||||||
VERSION:
|
{{ "VERSION" | color "" "heading" }}:
|
||||||
{{.Version}} Built at {{.Date}}
|
{{.Version | color "red" "" }} - {{.Date | color "red" ""}}
|
||||||
|
|
||||||
EXAMPLES:
|
{{ "EXAMPLES" | color "" "heading" }}:
|
||||||
doggo mrkaran.dev Query a domain using defaults
|
{{ .Name | color "green" "" }} {{ "mrkaran.dev" | color "cyan" "" }} Query a domain using defaults
|
||||||
doggo mrkaran.dev CNAME Looks up for a CNAME record.
|
{{ .Name | color "green" "" }} {{ "mrkaran.dev CNAME" | color "cyan" "" }} Looks up for a CNAME record
|
||||||
doggo mrkaran.dev MX @9.9.9.9 Uses a custom DNS resolver.
|
{{ .Name | color "green" "" }} {{ "mrkaran.dev MX @9.9.9.9" | color "cyan" "" }} Uses a custom DNS resolver
|
||||||
doggo -q mrkaran.dev -t MX -n 1.1.1.1 Using named arguments
|
{{ .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" "" }}
|
||||||
|
|
||||||
|
{{ "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)
|
||||||
|
|
||||||
|
{{ "Protocol Options" | color "" "heading" }}:
|
||||||
|
{{"-U, --udp " | color "yellow" ""}} Send queries via DNS over UDP protocol
|
||||||
|
{{"-T, --tcp " | color "yellow" ""}} Send queries via DNS over TCP protocol
|
||||||
|
{{"-S, --dot " | color "yellow" ""}} Send queries via DNS over TLS (DoT) protocol
|
||||||
|
{{"-H, --doh" | color "yellow" ""}} Send queries via DNS over HTTPS (DoH) protocol
|
||||||
|
|
||||||
|
{{ "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
|
||||||
`
|
`
|
||||||
|
|
||||||
func renderCustomHelp() {
|
func renderCustomHelp() {
|
||||||
|
@ -30,7 +54,31 @@ func renderCustomHelp() {
|
||||||
"Version": buildVersion,
|
"Version": buildVersion,
|
||||||
"Date": buildDate,
|
"Date": buildDate,
|
||||||
}
|
}
|
||||||
tmpl, err := template.New("test").Parse(AppHelpTemplate)
|
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)
|
||||||
|
},
|
||||||
|
}).Parse(AppHelpTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -70,7 +69,6 @@ func (hub *Hub) prepareQuestions() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchDomainList(d string, ndots int) ([]string, int, error) {
|
func fetchDomainList(d string, ndots int) ([]string, int, error) {
|
||||||
fmt.Println(ndots)
|
|
||||||
cfg, err := dns.ClientConfigFromFile(resolvers.DefaultResolvConfPath)
|
cfg, err := dns.ClientConfigFromFile(resolvers.DefaultResolvConfPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
|
|
@ -41,7 +41,6 @@ func (hub *Hub) outputJSON(out []Output, msgs []resolvers.Response) {
|
||||||
// get the questions
|
// get the questions
|
||||||
queries := make([]Query, 0, len(msgs))
|
queries := make([]Query, 0, len(msgs))
|
||||||
for _, ques := range hub.Questions {
|
for _, ques := range hub.Questions {
|
||||||
fmt.Println(ques.Qtype)
|
|
||||||
q := Query{
|
q := Query{
|
||||||
Name: ques.Name,
|
Name: ques.Name,
|
||||||
Type: dns.TypeToString[ques.Qtype],
|
Type: dns.TypeToString[ques.Qtype],
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 167 KiB |
Loading…
Reference in New Issue