Skip to content

Commit 068706a

Browse files
committed
(feat)Completions and documentation (#78)
Reviewed-on: https://git.froth.zone/sam/awl/pulls/78
1 parent 59a7fe6 commit 068706a

27 files changed

+372
-154
lines changed

.drone.jsonnet

+10-11
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ local testing(version, arch) = {
99
},
1010
steps: [
1111
{
12-
name: "submodules",
13-
image: "alpine/git",
12+
name: "compile",
13+
image: "golang:" + version,
1414
commands: [
15-
"git submodule update --init --recursive"
16-
]
15+
"make awl"
16+
],
1717
},
1818
{
1919
name: "lint",
2020
image: "rancher/drone-golangci-lint:latest",
2121
depends_on: [
22-
"submodules",
22+
"compile",
2323
],
2424
},
2525
{
@@ -29,7 +29,7 @@ local testing(version, arch) = {
2929
"make test-ci"
3030
],
3131
depends_on: [
32-
"submodules",
32+
"lint",
3333
],
3434
},
3535
{
@@ -39,7 +39,7 @@ local testing(version, arch) = {
3939
"make fuzz",
4040
],
4141
depends_on: [
42-
"submodules",
42+
"lint",
4343
],
4444
},
4545
],
@@ -68,7 +68,6 @@ local release() = {
6868
image: "alpine/git",
6969
commands : [
7070
"git fetch --tags",
71-
"git submodule update --init --recursive"
7271
]
7372
},
7473
{
@@ -95,9 +94,9 @@ local release() = {
9594

9695
[
9796
testing("1.19", "amd64"),
98-
testing("1.19", "arm64"),
99-
testing("1.18", "amd64"),
100-
testing("1.18", "arm64"),
97+
// testing("1.19", "arm64"),
98+
// testing("1.18", "amd64"),
99+
// testing("1.18", "arm64"),
101100

102101
release()
103102
]

.github/workflows/ghrelease.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ jobs:
1717
- name: Checkout submodules
1818
run: git submodule update --init --recursive
1919

20+
- name: Set up Go
21+
uses: actions/setup-go@v3
22+
with:
23+
go-version: 1.19
24+
2025
- name: Release with GoReleaser
2126
uses: goreleaser/goreleaser-action@v3
2227
with:

.github/workflows/test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ jobs:
2222
run: git submodule update --init --recursive
2323

2424
- name: Test
25-
run: go test -race -v ./...
25+
run: make test-ci

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "doc/wiki"]
22
path = doc/wiki
33
url = ../awl.wiki
4+
[submodule "pkg/awl-dns-git"]
5+
path = pkg/awl-dns-git
6+
url = https://aur.archlinux.org/awl-dns-git.git

.golangci.yaml

+7-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ linters:
3232
- predeclared
3333
- revive
3434
- staticcheck
35-
# - testpackage
35+
#- testpackage
3636
- whitespace
3737
- wrapcheck
3838
- wsl
@@ -49,26 +49,25 @@ linters-settings:
4949
errorCode: 1
5050
warningCode: 1
5151
rules:
52-
# rules can be uncommented after https://github.com/golangci/golangci-lint/issues/2997 is fixed
5352
- name: blank-imports
5453
- name: context-as-argument
55-
# - name: context-keys-type
54+
- name: context-keys-type
5655
- name: dot-imports
5756
- name: duplicated-imports
5857
- name: error-return
5958
- name: error-strings
6059
- name: error-naming
61-
# - name: errorf
60+
- name: errorf
6261
- name: exported
6362
- name: if-return
6463
- name: increment-decrement
65-
# - name: modifies-value-receiver
64+
- name: modifies-value-receiver
6665
- name: package-comments
6766
- name: range
6867
- name: receiver-naming
69-
# - name: time-naming
70-
# - name: unexported-return
71-
# - name: var-declaration
68+
- name: time-naming
69+
- name: unexported-return
70+
- name: var-declaration
7271
- name: var-naming
7372

7473
issues:

GNUmakefile

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
# SPDX-License-Identifier: BSD-3-Clause
2+
# GNU Makefile allowing for building on Windows (with GNU Make)
23

34
include template.mk
45

56
ifeq ($(OS),Windows_NT)
67
EXE := $(PROG).exe
78
else
89
EXE := $(PROG)
9-
1010
endif
1111

12-
$(PROG): $(SOURCES)
13-
$(GO) build -o $(EXE) $(GOFLAGS) .
14-
1512
## install: installs awl
13+
.PHONY: install
1614
ifeq ($(OS),Windows_NT)
1715
install:
1816
$(GO) install $(GOFLAGS) .
1917
else
2018
install: all
2119
install -Dm755 $(PROG) $(DESTDIR)$(PREFIX)/$(BIN)/$(PROG)
2220
install -Dm644 doc/$(PROG).1 $(DESTDIR)$(MAN)/man1/$(PROG).1
21+
# completions need to go in one specific place :)
22+
install -Dm644 completions/zsh.zsh $(DESTDIR)/$(PREFIX)/$(SHARE)/zsh/site-functions/_$(PROG)
2323
endif
24-
25-
.PHONY: install

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
include template.mk
55

6-
$(PROG): $(SOURCES)
7-
$(GO) build -o $(PROG) $(GOFLAGS) .
6+
EXE := $(PROG)
87

9-
## install: installs awl and the manpage, RUN AS ROOT
8+
## install: installs awl
9+
.PHONY: install
1010
install: all
1111
install -Dm755 $(PROG) $(DESTDIR)$(PREFIX)/$(BIN)/$(PROG)
1212
install -Dm644 doc/$(PROG).1 $(DESTDIR)$(MAN)/man1/$(PROG).1
13-
14-
.PHONY: install
13+
# completions need to go in one specific place :)
14+
install -Dm644 completions/zsh.zsh $(DESTDIR)/$(PREFIX)/$(SHARE)/zsh/site-functions/_$(PROG)

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Dependencies:
3434

3535
- Go >= 1.18
3636
- GNU/BSD make or Plan 9 mk (if using the makefile/mkfile)
37+
- scdoc (optional, for man page)
3738

3839
Using `go install` (recommended):
3940

@@ -45,7 +46,7 @@ Using the makefile:
4546

4647
```sh
4748
make
48-
sudo make install
49+
make && sudo make install
4950
```
5051

5152
## Contributing
@@ -59,4 +60,4 @@ Found a bug or want a new feature? Create an issue
5960

6061
### Licence
6162

62-
See [LICENCE](./LICENCE)
63+
Revised BSD, See [LICENCE](./LICENCE)

cli/cli.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ func ParseCLI(version string) (util.Options, error) {
3535
flag.PrintDefaults()
3636
}
3737

38-
// CLI flag
38+
// CLI flags
3939
var (
4040
port = flag.Int("port", 0, "`port` to make DNS query (default: 53 for UDP/TCP, 853 for TLS/QUIC)", flag.OptShorthand('p'), flag.OptDisablePrintDefault(true))
4141
query = flag.String("query", "", "domain name to `query` (default: .)", flag.OptShorthand('q'))
4242
class = flag.String("class", "IN", "DNS `class` to query", flag.OptShorthand('c'))
4343
qType = flag.String("qType", "", "`type` to query (default: A)", flag.OptShorthand('t'))
4444

45-
ipv4 = flag.Bool("4", false, "force IPv4", flag.OptShorthandStr("4"))
45+
ipv4 = flag.Bool("4", false, "force IPv4", flag.OptShorthand('4'))
4646
ipv6 = flag.Bool("6", false, "force IPv6", flag.OptShorthand('6'))
4747
reverse = flag.Bool("reverse", false, "do a reverse lookup", flag.OptShorthand('x'))
4848

@@ -57,7 +57,7 @@ func ParseCLI(version string) (util.Options, error) {
5757
cookie = flag.Bool("no-cookie", false, "disable sending EDNS cookie (default: cookie sent)")
5858
tcpKeepAlive = flag.Bool("keep-alive", false, "send EDNS TCP keep-alive")
5959
udpBufSize = flag.Uint16("buffer-size", 1232, "set EDNS UDP buffer size", flag.OptShorthand('b'))
60-
mbzflag = flag.String("zflag", "0", "set EDNS z-flag")
60+
mbzflag = flag.String("zflag", "0", "set EDNS z-flag `value`")
6161
subnet = flag.String("subnet", "", "set EDNS subnet")
6262
padding = flag.Bool("pad", false, "set EDNS padding")
6363

cli/dig.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func ParseDig(arg string, opts *util.Options) error {
117117
opts.Display.Authority = isNo
118118
opts.Display.Additional = isNo
119119
opts.Display.Statistics = isNo
120-
case "idnout":
120+
case "idnin", "idnout":
121121
opts.Display.UcodeTranslate = isNo
122122

123123
default:

cli/docs.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
13
/*
24
Package cli is the CLI part of the package, including both POSIX
35
flag parsing and dig-like flag parsing.

cli/misc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ func ParseMiscArgs(args []string, opts *util.Options) error {
117117

118118
if err != nil {
119119
// :^)
120-
opts.Logger.Warn("Could not query system for server. Using default")
121-
opts.Request.Server = "95.216.99.249"
120+
opts.Logger.Warn("Could not query system for server. Using localhost")
121+
opts.Request.Server = "127.0.0.1"
122122
} else {
123123
// Make sure that if IPv4 or IPv6 is asked for it actually uses it
124124
harmful:

completions/zsh.zsh

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#compdef awl
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
local curcontext="$curcontext" state line expl
5+
local -a alts args
6+
[[ -prefix + ]] && args=(
7+
'*+'{no,}'tcp[use TCP instead of UDP for queries]'
8+
'*+'{no,}'ignore[ignore truncation in UDP responses]'
9+
'*+'{no,}'tls[use DNS-over-TLS for queries]'
10+
'*+'{no,}'dnscrypt[use DNSCrypt for queries]'
11+
'*+'{no,}'https[use DNS-over-HTTPS for queries]'
12+
'*+'{no,}'quic[use DNS-over-QUIC for queries]'
13+
'*+'{no,}'aaonly[set aa flag in the query]'
14+
'*+'{no,}'additional[print additional section of a reply]'
15+
'*+'{no,}'adflag[set the AD (authentic data) bit in the query]'
16+
'*+'{no,}'cdflag[set the CD (checking disabled) bit in the query]'
17+
'*+'{no,}'cookie[add a COOKIE option to the request]'
18+
'*+edns=[specify EDNS version for query]:version (0-255)'
19+
'*+noedns[clear EDNS version to be sent]'
20+
'*+ednsflags=[set EDNS flags bits]:flags'
21+
# '*+ednsopt=[specify EDNS option]:code point'
22+
'*+noedns[clear EDNS options to be sent]'
23+
'*+'{no,}'expire[send an EDNS Expire option]'
24+
# '*+'{no,}'idnin[set processing of IDN domain names on input]'
25+
'*+'{no,}'idnout[set conversion of IDN puny code on output]'
26+
'*+'{no,}'keepalive[request EDNS TCP keepalive]'
27+
'*+'{no,}'keepopen[keep TCP socket open between queries]'
28+
'*+'{no,}'recurse[set the RD (recursion desired) bit in the query]'
29+
# '*+'{no,}'nssearch[search all authoritative nameservers]'
30+
# '*+'{no,}'trace[trace delegation down from root]'
31+
# '*+'{no,}'cmd[print initial comment in output]'
32+
'*+'{no,}'short[print terse output]'
33+
'*+'{no,}'identify[print IP and port of responder]'
34+
'*+'{no,}'comments[print comment lines in output]'
35+
'*+'{no,}'stats[print statistics]'
36+
'*+padding[set padding block size]:size [0]'
37+
'*+'{no,}'qr[print query as it was sent]'
38+
'*+'{no,}'question[print question section of a query]'
39+
'*+'{no,}'raflag[set RA flag in the query]'
40+
'*+'{no,}'answer[print answer section of a reply]'
41+
'*+'{no,}'authority[print authority section of a reply]'
42+
'*+'{no,}'all[set all print/display flags]'
43+
'*+'{no,}'subnet=[send EDNS client subnet option]:addr/prefix-length'
44+
'*+'{no,}'tcflag[set TC flag in the query]'
45+
'*+time=[set query timeout]:timeout (seconds) [1]'
46+
'*+timeout=[set query timeout]:timeout (seconds) [1]'
47+
'*+tries=[specify number of UDP query attempts]:tries [3]'
48+
'*+retry=[specify number of UDP query retries]:retries [2]'
49+
# '*+'{no,}'rrcomments[set display of per-record comments]'
50+
# '*+ndots=[specify number of dots to be considered absolute]:dots'
51+
'*+bufsize=[specify UDP buffer size]:size (bytes)'
52+
'*+'{no,}'dnssec[enable DNSSEC]'
53+
'*+'{no,}'nsid[include EDNS name server ID request in query]'
54+
'*+'{no,}'class[display the class whening printing the answer]'
55+
'*+'{no,}'ttlid[display the TTL whening printing the record]'
56+
'*+'{no,}'ttlunits[display the TTL in human-readable units]'
57+
# '*+'{no,}'unknownformat[print RDATA in RFC 3597 "unknown" format]'
58+
'*+'{no,}'json[present the results as JSON]'
59+
'*+'{no,}'xml[present the results as XML]'
60+
'*+'{no,}'yaml[present the results as YAML]'
61+
'*+'{no,}'zflag[set Z flag in query]'
62+
)
63+
# TODO: Add the regular (POSIX/GNU) flags
64+
_arguments -s -C $args \
65+
'(- *)-'{h,-help}'[display help information]' \
66+
'(- *)-'{V,-version}'[display version information]' \
67+
'-'{v,-verbosity}'=+[set verbosity to custom level]:verbosity:compadd -M "m\:{\-1-3}={\-1-3}" - \-1 0 1 2 3' \
68+
'-'{v,-verbosity}'+[set verbosity to info]' \
69+
'*-'{p,-port}'+[specify port number]:port:_ports' \
70+
'*-'{q,-query}'+[specify host name to query]:host:_hosts' \
71+
'*-'{c,-class}'+[specify class]:class:compadd -M "m\:{a-z}={A-Z}" - IN CS CH HS' \
72+
'*-'{t,-qType}'+[specify type]:type:_dns_types' \
73+
'*-4+[force IPv4 only]' \
74+
'*-6+[force IPv6 only]' \
75+
'*-'{x,-reverse}'+[reverse lookup]' \
76+
'*--timeout+[timeout in seconds]:number [1]' \
77+
'*--retry+[specify number of UDP query retries]:number [2]' \
78+
'*--no-edns+[disable EDNS]' \
79+
'*--edns-ver+[specify EDNS version for query]:version (0-255) [0]' \
80+
'*-'{D,-dnssec}'+[enable DNSSEC]' \
81+
'*--expire+[send EDNS expire]' \
82+
'*-'{n,-nsid}'+[include EDNS name server ID request in query]' \
83+
'*--no-cookie+[disable sending EDNS cookie]' \
84+
'*--keep-alive+[request EDNS TCP keepalive]' \
85+
'*-'{b,-buffer-size}'+[specify UDP buffer size]:size (bytes) [1232]' \
86+
'*--zflag+[set EDNS z-flag]:decimal, hex or octal [0]' \
87+
'*--subnet+[set EDNS client subnet]:addr/prefix-length' \
88+
'*--no-truncate+[ignore truncation in UDP responses]' \
89+
'*--tcp+[use TCP instead of UDP for queries]' \
90+
'*--dnscrypt+[use DNSCrypt for queries]' \
91+
'*-'{T,-tls}'+[use DNS-over-TLS for queries]' \
92+
'*-'{H,-https}'+[use DNS-over-HTTPS for queries]' \
93+
'*-'{Q,-quic}'+[use DNS-over-QUIC for queries]' \
94+
'*--tls-no-verify+[disable TLS verification]' \
95+
'*--tls-host+[set TLS lookup hostname]:host:_hosts' \
96+
'*-'{s,-short}'+[print terse output]' \
97+
'*-'{j,-json}'+[present the results as JSON]' \
98+
'*-'{x,-xml}'+[present the results as XML]' \
99+
'*-'{y,-yaml}'+[present the results as YAML]' \
100+
'*: :->args' && ret=0
101+
102+
if [[ -n $state ]]; then
103+
if compset -P @; then
104+
_wanted hosts expl 'DNS server' _hosts && ret=0;
105+
else
106+
_alternative 'hosts:host:_hosts' 'types:query type:_dns_types' && ret=0
107+
fi
108+
fi
109+
110+
return ret

conf/docs.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
13
/*
24
Package conf contains helper functions for getting local nameservers
35

0 commit comments

Comments
 (0)