feat: Parse args which are not flags

pull/2/head
Karan Sharma 2020-12-13 21:30:54 +05:30
parent 9d2245f72e
commit 646829a72c
4 changed files with 8 additions and 6 deletions

View File

@ -34,7 +34,7 @@
- [ ] Colorize
- [ ] Add different commands
- [x] Add client transport options
- [ ] Fix an issue while loading free form args, where the same records are being added twice
- [x] Fix an issue while loading free form args, where the same records are being added twice
## Tests

View File

@ -32,7 +32,7 @@ func main() {
f.StringSliceP("query", "q", []string{}, "Domain name to query")
f.StringSliceP("type", "t", []string{}, "Type of DNS record to be queried (A, AAAA, MX etc)")
f.StringSliceP("class", "c", []string{}, "Network class of the DNS record to be queried (IN, CH, HS etc)")
f.StringSliceP("nameservers", "n", []string{}, "Address of the nameserver to send packets to")
f.StringSliceP("nameserver", "n", []string{}, "Address of the nameserver to send packets to")
// Protocol Options
f.BoolP("udp", "U", false, "Use the DNS protocol over UDP")
@ -57,6 +57,9 @@ func main() {
f.Usage()
hub.Logger.Exit(2)
}
hub.FreeArgs = f.Args()
// set log level
if k.Bool("debug") {
// Set logger level

View File

@ -11,6 +11,7 @@ type Hub struct {
Logger *logrus.Logger
Version string
QueryFlags QueryFlags
FreeArgs []string
Questions []dns.Question
Resolver resolvers.Resolver
}
@ -20,7 +21,7 @@ type QueryFlags struct {
QNames []string `koanf:"query"`
QTypes []string `koanf:"type"`
QClasses []string `koanf:"class"`
Nameservers []string `koanf:"namserver"`
Nameservers []string `koanf:"nameserver"`
IsDOH bool `koanf:"doh"`
IsDOT bool `koanf:"dot"`
IsUDP bool `koanf:"udp"`

View File

@ -1,7 +1,6 @@
package main
import (
"os"
"strings"
"github.com/miekg/dns"
@ -33,8 +32,7 @@ func (hub *Hub) loadQueryArgs() error {
// options. In case an argument isn't able to fit in any of the existing
// pattern it is considered to be a "query name".
func (hub *Hub) loadFreeArgs() error {
args := os.Args[1:]
for _, arg := range args {
for _, arg := range hub.FreeArgs {
if strings.HasPrefix(arg, "--") || strings.HasPrefix(arg, "-") {
continue
}