Skip to content

Commit

Permalink
feat: add short-ttls option (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Oct 29, 2023
1 parent 40140d5 commit debc3c6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ Application Options:
--txtconcat Concatenate TXT responses
--qid= Set query ID (-1 for random) (default: -1)
--recaxfr Perform recursive AXFR
-f, --format= Output format (pretty, json, yaml, raw)
(default: pretty)
--pretty-ttls Format TTLs in human readable format (default:
true)
-f, --format= Output format (pretty, json, yaml, raw) (default: pretty)
--pretty-ttls Format TTLs in human readable format (default: true)
--short-ttls Remove zero components of pretty TTLs. (24h0m0s->24h) (default: true)
--color Enable color output
--question Show question section
--answer Show answer section (default: true)
Expand All @@ -65,13 +64,11 @@ Application Options:
--all Show all sections and statistics
-w Resolve ASN/ASName for A and AAAA records
-r, --short Show record values only
-R, --resolve-ips Resolve PTR records for IP addresses in A and
AAAA records
-R, --resolve-ips Resolve PTR records for IP addresses in A and AAAA records
--aa Set AA (Authoritative Answer) flag in query
--ad Set AD (Authentic Data) flag in query
--cd Set CD (Checking Disabled) flag in query
--rd Set RD (Recursion Desired) flag in query
(default: true)
--rd Set RD (Recursion Desired) flag in query (default: true)
--ra Set RA (Recursion Available) flag in query
--z Set Z (Zero) flag in query
--t Set TC (Truncated) flag in query
Expand All @@ -91,12 +88,10 @@ Application Options:
--quic-no-pmtud Disable QUIC PMTU discovery
--quic-no-length-prefix Don't add RFC 9250 compliant length prefix
--dnscrypt-tcp Use TCP for DNSCrypt (default UDP)
--dnscrypt-udp-size= Maximum size of a DNS response this client can
sent or receive (default: 0)
--dnscrypt-udp-size= Maximum size of a DNS response this client can sent or receive (default: 0)
--dnscrypt-key= DNSCrypt public key
--dnscrypt-provider= DNSCrypt provider name
--default-rr-types= Default record types (default: A, AAAA, NS, MX,
TXT, CNAME)
--default-rr-types= Default record types (default: A, AAAA, NS, MX, TXT, CNAME)
--udp-buffer= Set EDNS0 UDP size in query (default: 1232)
-v, --verbose Show verbose log messages
--trace Show trace log messages
Expand Down
1 change: 1 addition & 0 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Flags struct {
// Output
Format string `short:"f" long:"format" description:"Output format (pretty, json, yaml, raw)" default:"pretty"`
PrettyTTLs bool `long:"pretty-ttls" description:"Format TTLs in human readable format (default: true)"`
ShortTTLs bool `long:"short-ttls" description:"Remove zero components of pretty TTLs. (24h0m0s->24h) (default: true)"`
Color bool `long:"color" description:"Enable color output"`
ShowQuestion bool `long:"question" description:"Show question section"`
ShowAnswer bool `long:"answer" description:"Show answer section (default: true)"`
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func clearOpts() {
opts.RecursionDesired = true
opts.ShowAnswer = true
opts.PrettyTTLs = true
opts.ShortTTLs = true

// Enable color output if stdout is a terminal
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
Expand Down
4 changes: 4 additions & 0 deletions output/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func (p Printer) printPrettyRR(a dns.RR, doWhois, doResolveIPs bool) {
ttl := fmt.Sprintf("%d", a.Header().Ttl)
if p.Opts.PrettyTTLs {
ttl = (time.Duration(a.Header().Ttl) * time.Second).String()
if p.Opts.ShortTTLs {
ttl = strings.ReplaceAll(ttl, "0s", "")
ttl = strings.ReplaceAll(ttl, "0m", "")
}
}

// Copy val now before modifying it with a suffix
Expand Down

0 comments on commit debc3c6

Please sign in to comment.