Skip to content

Commit 51e78c5

Browse files
committed
fix: completions
1 parent b512e3f commit 51e78c5

File tree

1 file changed

+82
-44
lines changed

1 file changed

+82
-44
lines changed

cmd/doggo/completions.go

Lines changed: 82 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -32,75 +32,113 @@ _doggo() {
3232
COMPREPLY=( $(compgen -W "true false" -- ${cur}) )
3333
return 0
3434
;;
35+
-n|--nameserver)
36+
COMPREPLY=( $(compgen -W "1.1.1.1 8.8.8.8 9.9.9.9" -- ${cur}) )
37+
return 0
38+
;;
3539
esac
3640
3741
if [[ ${cur} == -* ]]; then
3842
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
3943
return 0
4044
fi
45+
46+
COMPREPLY=( $(compgen -A hostname -- ${cur}) )
4147
}
4248
4349
complete -F _doggo doggo
4450
`
4551

4652
zshCompletion = `
47-
#compdef _doggo doggo
53+
#compdef doggo
4854
4955
_doggo() {
50-
_arguments \
51-
"(- 1 *)"{-v,--version}"[Show version of doggo]" \
52-
"(- 1 *)"{-h,--help}"[Show list of command-line options]" \
53-
{-q,--query=}"[Hostname to query the DNS records for]::_hosts" \
54-
{-t,--type=}"[Type of the DNS Record]:(record type):(A AAAA CAA CNAME HINFO MX NS PTR SOA SRV TXT)" \
55-
{-n,--nameserver=}"[Address of a specific nameserver to send queries to]::_hosts;" \
56-
{-c,--class=}"[Network class of the DNS record being queried]:(network class):(IN CH HS)" \
57-
{-r,--reverse}"[Performs a DNS Lookup for an IPv4 or IPv6 address]" \
58-
--strategy="[Strategy to query nameserver listed in etc/resolv.conf]:(strategy):(all random first)" \
59-
--ndots="[Number of requred dots in hostname to assume FQDN]:(number of dots):()" \
60-
--search"[Defaults to true. Set --search=false to not use the search list defined in resolve.conf]:(setting):(true false)" \
61-
--timeout"[Timeout (in seconds) for the resolver to return a response]:(seconds):()" \
62-
{-4,--ipv4}"[Use IPv4 only]" \
63-
{-6,--ipv6}"[Use IPv6 only]" \
64-
--tls-hostname="[Hostname used for verification of certificate incase the provided DoT nameserver is an IP]::_hosts" \
65-
--skip-hostname-verification"[Skip TLS hostname verification in case of DoT lookups]" \
66-
{-J,--json}"[Format the output as JSON]" \
67-
--short"[Shows only the response section in the output]" \
68-
--color="[Defaults to true. Set --color=false to disable colored output]:(setting):(true false)" \
69-
--debug"[Enable debug logging]:(setting):(true false)" \
70-
--time"[Shows how long the response took from the server]" \
71-
'*:hostname:_hosts'
56+
local -a commands
57+
commands=(
58+
'completions:Generate shell completion scripts'
59+
)
60+
61+
_arguments -C \
62+
'(-v --version)'{-v,--version}'[Show version of doggo]' \
63+
'(-h --help)'{-h,--help}'[Show list of command-line options]' \
64+
'(-q --query)'{-q,--query}'[Hostname to query the DNS records for]:hostname:_hosts' \
65+
'(-t --type)'{-t,--type}'[Type of the DNS Record]:record type:(A AAAA CAA CNAME HINFO MX NS PTR SOA SRV TXT)' \
66+
'(-n --nameserver)'{-n,--nameserver}'[Address of a specific nameserver to send queries to]:nameserver:(1.1.1.1 8.8.8.8 9.9.9.9)' \
67+
'(-c --class)'{-c,--class}'[Network class of the DNS record being queried]:network class:(IN CH HS)' \
68+
'(-r --reverse)'{-r,--reverse}'[Performs a DNS Lookup for an IPv4 or IPv6 address]' \
69+
'--strategy[Strategy to query nameserver listed in etc/resolv.conf]:strategy:(all random first)' \
70+
'--ndots[Number of required dots in hostname to assume FQDN]:number of dots' \
71+
'--search[Use the search list defined in resolv.conf]:setting:(true false)' \
72+
'--timeout[Timeout (in seconds) for the resolver to return a response]:seconds' \
73+
'(-4 --ipv4)'{-4,--ipv4}'[Use IPv4 only]' \
74+
'(-6 --ipv6)'{-6,--ipv6}'[Use IPv6 only]' \
75+
'--tls-hostname[Hostname used for verification of certificate incase the provided DoT nameserver is an IP]:hostname:_hosts' \
76+
'--skip-hostname-verification[Skip TLS hostname verification in case of DoT lookups]' \
77+
'(-J --json)'{-J,--json}'[Format the output as JSON]' \
78+
'--short[Shows only the response section in the output]' \
79+
'--color[Colored output]:setting:(true false)' \
80+
'--debug[Enable debug logging]' \
81+
'--time[Shows how long the response took from the server]' \
82+
'*:hostname:_hosts' \
83+
&& ret=0
84+
85+
case $state in
86+
(commands)
87+
_describe -t commands 'doggo commands' commands && ret=0
88+
;;
89+
esac
90+
91+
return ret
7292
}
93+
94+
_doggo
7395
`
7496

7597
fishCompletion = `
76-
# Meta options
77-
complete -c doggo -l 'version' -d "Show version of doggo"
78-
complete -c doggo -l 'help' -d "Show list of command-line options"
98+
function __fish_doggo_no_subcommand
99+
set cmd (commandline -opc)
100+
if [ (count $cmd) -eq 1 ]
101+
return 0
102+
end
103+
return 1
104+
end
79105
80-
# Single line all options
81-
complete -c doggo -x -a "(__fish_print_hostnames) A AAAA CAA CNAME HINFO MX NS PTR SOA SRV TXT IN CH HS"
106+
# Meta options
107+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'version' -d "Show version of doggo"
108+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'help' -d "Show list of command-line options"
82109
83110
# Query options
84-
complete -c doggo -s 'q' -l 'query' -d "Hostname to query the DNS records for" -x -a "(__fish_print_hostnames)"
85-
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"
86-
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)"
87-
complete -c doggo -s 'c' -l 'class' -d "Network class of the DNS record being queried" -x -a "IN CH HS"
88-
89-
# Transport options
90-
complete -c doggo -x -a "@udp:// @tcp:// @https:// @tls:// @sdns://" -d "Select the protocol for resolving queries"
111+
complete -c doggo -n '__fish_doggo_no_subcommand' -s 'q' -l 'query' -d "Hostname to query the DNS records for" -x -a "(__fish_print_hostnames)"
112+
complete -c doggo -n '__fish_doggo_no_subcommand' -s 't' -l 'type' -d "Type of the DNS Record" -x -a "A AAAA CAA CNAME HINFO MX NS PTR SOA SRV TXT"
113+
complete -c doggo -n '__fish_doggo_no_subcommand' -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"
114+
complete -c doggo -n '__fish_doggo_no_subcommand' -s 'c' -l 'class' -d "Network class of the DNS record being queried" -x -a "IN CH HS"
115+
complete -c doggo -n '__fish_doggo_no_subcommand' -s 'r' -l 'reverse' -d "Performs a DNS Lookup for an IPv4 or IPv6 address"
91116
92117
# Resolver options
93-
complete -c doggo -l 'ndots' -d "Specify ndots parameter. Takes value from /etc/resolv.conf if using the system namesever or 1 otherwise"
94-
complete -c doggo -l 'search' -d "Use the search list defined in resolv.conf. Defaults to true. Set --search=false to disable search list"
95-
complete -c doggo -l 'timeout' -d "Specify timeout (in seconds) for the resolver to return a response"
96-
complete -c doggo -s '-4' -l 'ipv4' -d "Use IPv4 only"
97-
complete -c doggo -s '-6' -l 'ipv6' -d "Use IPv6 only"
118+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'strategy' -d "Strategy to query nameserver listed in etc/resolv.conf" -x -a "all random first"
119+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'ndots' -d "Specify ndots parameter"
120+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'search' -d "Use the search list defined in resolv.conf" -x -a "true false"
121+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'timeout' -d "Specify timeout (in seconds) for the resolver to return a response"
122+
complete -c doggo -n '__fish_doggo_no_subcommand' -s '4' -l 'ipv4' -d "Use IPv4 only"
123+
complete -c doggo -n '__fish_doggo_no_subcommand' -s '6' -l 'ipv6' -d "Use IPv6 only"
98124
99125
# Output options
100-
complete -c doggo -s 'J' -l 'json' -d "Format the output as JSON"
101-
complete -c doggo -l 'color' -d "Defaults to true. Set --color=false to disable colored output"
102-
complete -c doggo -l 'debug' -d "Enable debug logging"
103-
complete -c doggo -l 'time' -d "Shows how long the response took from the server"
126+
complete -c doggo -n '__fish_doggo_no_subcommand' -s 'J' -l 'json' -d "Format the output as JSON"
127+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'short' -d "Shows only the response section in the output"
128+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'color' -d "Colored output" -x -a "true false"
129+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'debug' -d "Enable debug logging"
130+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'time' -d "Shows how long the response took from the server"
131+
132+
# Transport options
133+
complete -c doggo -n '__fish_doggo_no_subcommand' -x -a "@udp:// @tcp:// @https:// @tls:// @sdns://" -d "Select the protocol for resolving queries"
134+
135+
# TLS options
136+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'tls-hostname' -d "Hostname for certificate verification" -x -a "(__fish_print_hostnames)"
137+
complete -c doggo -n '__fish_doggo_no_subcommand' -l 'skip-hostname-verification' -d "Skip TLS hostname verification in case of DoT lookups"
138+
139+
# Completions command
140+
complete -c doggo -n '__fish_doggo_no_subcommand' -a completions -d "Generate shell completion scripts"
141+
complete -c doggo -n '__fish_seen_subcommand_from completions' -a "bash zsh fish" -d "Shell type"
104142
`
105143
)
106144

0 commit comments

Comments
 (0)