diff options
| author | Tero Marttila <[email protected]> | 2016-06-19 20:10:19 +0300 |
|---|---|---|
| committer | Tero Marttila <[email protected]> | 2016-06-19 20:10:19 +0300 |
| commit | 8d38f299ad81d752e68b2cdce62c9385d0a2cbdf (patch) | |
| tree | b15fc90d12375770217c4a0af7f31de9ec635d43 | |
| parent | b2f9c977719626bebd9c9f9f7e52e50f2514ace7 (diff) | |
take name as posarg, default for --tsig-name
| -rw-r--r-- | main.go | 24 |
1 files changed, 15 insertions, 9 deletions
@@ -20,19 +20,19 @@ type Options struct { TSIGAlgorithm TSIGAlgorithm `long:"tsig-algorithm" default:"hmac-sha1."` Zone string `long:"zone" description:"Zone to update"` - Name string `long:"name" description:"Name to update"` TTL int `long:"ttl" default:"60"` + + Args struct { + Name string `description:"DNS Name to update"` + } `positional-args:"yes"` } func main() { var options Options - if args, err := flags.Parse(&options); err != nil { + if _, err := flags.Parse(&options); err != nil { log.Fatalf("flags.Parse: %v", err) os.Exit(1) - } else if len(args) > 0 { - log.Fatalf("Usage: no args") - os.Exit(1) } var update = Update{ @@ -40,14 +40,20 @@ func main() { timeout: options.Timeout, } - if err := update.Init(options.Name, options.Zone, options.Server); err != nil { + if err := update.Init(options.Args.Name, options.Zone, options.Server); err != nil { log.Fatalf("init: %v", err) } - if options.TSIGName != "" { - log.Printf("using TSIG: %v (algo=%v)", options.TSIGName, options.TSIGAlgorithm) + if options.TSIGSecret != "" { + var name = options.TSIGName + + if name == "" { + name = options.Args.Name + } + + log.Printf("using TSIG: %v (algo=%v)", name, options.TSIGAlgorithm) - update.InitTSIG(options.TSIGName, options.TSIGSecret, options.TSIGAlgorithm) + update.InitTSIG(name, options.TSIGSecret, options.TSIGAlgorithm) } // addrs |
