feat: Add shell completions for zsh,fish

pull/18/head v0.3.9
Karan Sharma 2021-04-21 11:40:21 +05:30
parent 45dd2e2af2
commit 7b858c5a93
5 changed files with 60 additions and 5 deletions

View File

@ -40,6 +40,7 @@ archives:
files:
- README.md
- LICENSE
- completions/
snapcrafts:
- name_template: "{{ .ProjectName }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"

View File

@ -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))

View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"os"
"time"
@ -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 {
@ -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

View File

@ -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"

View File

@ -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