awl/cli/dig.go
Sam Therapy 1b5d5a3fed
Some checks failed
continuous-integration/drone/push Build is failing
Do "a few things"
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2022-07-20 23:14:15 +02:00

57 lines
1.2 KiB
Go

// SPDX-License-Identifier: BSD-3-Clause
package cli
import (
"fmt"
"strings"
)
// Parse dig-like commands and set the options as such
func ParseDig(arg string, opts *Options) error {
// returns true if the flag starts with a no
isNo := !strings.HasPrefix(arg, "no")
switch arg {
// Set DNS query flags
case "aaflag", "aaonly", "noaaflag", "noaaonly":
opts.AA = isNo
case "adflag", "noadflag":
opts.AD = isNo
case "cdflag", "nocdflag":
opts.CD = isNo
case "qrflag", "noqrflag":
opts.QR = isNo
case "raflag", "noraflag":
opts.RA = isNo
case "rdflag", "recurse", "nordflag", "norecurse":
opts.RD = isNo
case "tcflag", "notcflag":
opts.TC = isNo
case "zflag", "nozflag":
opts.Z = isNo
// End DNS query flags
case "dnssec", "nodnssec":
opts.DNSSEC = isNo
case "tcp", "vc", "notcp", "novc":
opts.TCP = isNo
case "ignore", "noignore":
// Invert (ignore truncation when true)
opts.Truncate = !isNo
// Formatting
case "short", "noshort":
opts.Short = isNo
case "json", "nojson":
opts.JSON = isNo
case "xml", "noxml":
opts.XML = isNo
case "yaml", "noyaml":
opts.YAML = isNo
// End formatting
default:
return fmt.Errorf("dig: Unknown flag given")
}
return nil
}