Skip to content

Commit

Permalink
feat: Add shell completions for zsh,fish
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-karan committed Apr 21, 2021
1 parent 45dd2e2 commit 7b858c5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ archives:
files:
- README.md
- LICENSE
- completions/

snapcrafts:
- name_template: "{{ .ProjectName }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
Expand Down
9 changes: 4 additions & 5 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@
# Future Release

- [ ] Support obscure protocol tweaks in `dig`
- [ ] Read from file with `-f`
- [x] Support more DNS Record Types
- [ ] Shell completions
- [ ] bash
- [ ] zsh
- [ ] fish
- [x] Shell completions
- [x] zsh
- [x] fish
- [ ] Add tests for Resolvers.
- [ ] Add tests for CLI Output.
- [ ] Homebrew - Goreleaser
- [ ] Add support for `dig +trace` like functionality.
- [x] Separate Authority/Answer in JSON output.
- [x] Error on NXDomain (Related upstream [bug](https://github.com/miekg/dns/issues/1198))
9 changes: 9 additions & 0 deletions cmd/doggo/cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"
"time"

Expand Down Expand Up @@ -50,6 +51,8 @@ func main() {
f.Bool("color", true, "Show colored output")
f.Bool("debug", false, "Enable debug mode")

f.Bool("version", false, "Show version of doggo")

// Parse and Load Flags.
err := f.Parse(os.Args[1:])
if err != nil {
Expand All @@ -62,6 +65,12 @@ func main() {
app.Logger.Exit(2)
}

// If version flag is set, output version and quit.
if k.Bool("version") {
fmt.Printf("%s - %s\n", buildVersion, buildDate)
app.Logger.Exit(0)
}

// Set log level.
if k.Bool("debug") {
// Set logger level
Expand Down
28 changes: 28 additions & 0 deletions completions/doggo.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Meta options
complete -c doggo -l 'version' -d "Show version of doggo"
complete -c doggo -l 'help' -d "Show list of command-line options"

# Single line all options
complete -c doggo -x -a "(__fish_print_hostnames) A AAAA CAA CNAME HINFO MX NS PTR SOA SRV TXT IN CH HS"

# Query options
complete -c doggo -s 'q' -l 'query' -d "Hostname to query the DNS records for" -x -a "(__fish_print_hostnames)"
complete -c doggo -s 't' -l 'type' -d "Type of the DNS Record" -x -a "A AAAA CAA CNAME HINFO MX NS PTR SOA SRV TXT"
complete -c doggo -s 'n' -l 'nameserver' -d "Address of a specific nameserver to send queries to" -x -a "1.1.1.1 8.8.8.8 9.9.9.9 (__fish_print_hostnames)"
complete -c doggo -s 'c' -l 'class' -d "Network class of the DNS record being queried" -x -a "IN CH HS"

# Transport options
complete -c doggo -x -a "@udp:// @tcp:// @https:// @tls://" -d "Select the protocol for resolving queries"

# Resolver options
complete -c doggo -l 'ndots' -d "Specify ndots parameter. Takes value from /etc/resolv.conf if using the system namesever or 1 otherwise"
complete -c doggo -l 'search' -d "Use the search list defined in resolv.conf. Defaults to true. Set --search=false to disable search list"
complete -c doggo -l 'timeout' -d "Specify timeout (in seconds) for the resolver to return a response"
complete -c doggo -s '-4' -l 'ipv4' -d "Use IPv4 only"
complete -c doggo -s '-6' -l 'ipv6' -d "Use IPv6 only"

# Output options
complete -c doggo -s 'J' -l 'json' -d "Format the output as JSON"
complete -c doggo -l 'color' -d "Defaults to true. Set --color=false to disable colored output"
complete -c doggo -l 'debug' -d "Enable debug logging"
complete -c doggo -l 'time' -d "Shows how long the response took from the server"
18 changes: 18 additions & 0 deletions completions/doggo.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#compdef doggo

__doggo() {
_arguments \
"(- 1 *)"{-v,--version}"[Show version of doggo]" \
"(- 1 *)"{-\?,--help}"[Show list of command-line options]" \
{-q,--query}"[Hostname to query the DNS records for]::_hosts" \
{-t,--type}"[Type of the DNS Record]:(record type):(A AAAA CAA CNAME HINFO MX NS PTR SOA SRV TXT)" \
{-n,--nameserver}"[Address of a specific nameserver to send queries to]::_hosts;" \
{-c,--class}"[Network class of the DNS record being queried]:(network class):(IN CH HS)" \
{-J,--json}"[Format the output as JSON]" \
{--color}"[Defaults to true. Set --color=false to disable colored output]:(setting):(true false)" \
{--debug}"[Enable debug logging]:(setting):(true false)" \
--time"[Shows how long the response took from the server"] \
'*:filename:_hosts'
}

__doggo

0 comments on commit 7b858c5

Please sign in to comment.