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 - [ ] Colorize
- [ ] Add different commands - [ ] Add different commands
- [x] Add client transport options - [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 ## Tests

View File

@ -32,7 +32,7 @@ func main() {
f.StringSliceP("query", "q", []string{}, "Domain name to query") 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("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("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 // Protocol Options
f.BoolP("udp", "U", false, "Use the DNS protocol over UDP") f.BoolP("udp", "U", false, "Use the DNS protocol over UDP")
@ -57,6 +57,9 @@ func main() {
f.Usage() f.Usage()
hub.Logger.Exit(2) hub.Logger.Exit(2)
} }
hub.FreeArgs = f.Args()
// set log level // set log level
if k.Bool("debug") { if k.Bool("debug") {
// Set logger level // Set logger level

View File

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

View File

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