diff --git a/cmd/main.go b/cmd/main.go index 191c43e..0a8ab9b 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -34,5 +34,5 @@ func main() { } data := resolver.PerformZoneTransfer(cfg, debug) - shell.CreateShellAliases(data, user, cfg) + shell.CreateShellAliases(data, user, cfg, debug) } diff --git a/pkg/resolver/resolver.go b/pkg/resolver/resolver.go index a78d74e..c56d6b4 100644 --- a/pkg/resolver/resolver.go +++ b/pkg/resolver/resolver.go @@ -12,7 +12,10 @@ import ( ) // LookupName returns IPv4 address from A record or error. -func lookupName(fqdn, serverAddr string) (string, error) { +func lookupName(fqdn, serverAddr string, debug bool) (string, error) { + if debug { + defer utils.LogElapsedTime("Lookup Name") + } m := &dns.Msg{} m.SetQuestion(dns.Fqdn(fqdn), dns.TypeA) in, err := dns.Exchange(m, serverAddr) @@ -52,7 +55,7 @@ func PerformZoneTransfer(config config.Config, debug bool) []string { switch v := a.(type) { case *dns.TXT: hostname = v.Hdr.Name - cip, err := lookupName(strings.TrimRight(v.Hdr.Name, "."), server) + cip, err := lookupName(strings.TrimRight(v.Hdr.Name, "."), server, debug) if err != nil || cip == "" { continue } @@ -61,7 +64,7 @@ func PerformZoneTransfer(config config.Config, debug bool) []string { ip = v.A.String() hostname = v.Hdr.Name case *dns.CNAME: - cip, err := lookupName(v.Target, server) + cip, err := lookupName(v.Target, server, debug) if err != nil || cip == "" { continue } diff --git a/pkg/shell/shell.go b/pkg/shell/shell.go index 0d70bab..eaa1415 100644 --- a/pkg/shell/shell.go +++ b/pkg/shell/shell.go @@ -2,13 +2,17 @@ package shell import ( "fmt" + "rfi-sower/pkg/utils" "strings" "git.linuxrocker.com/mattburchett/go_tab-magic/pkg/config" ) // CreateShellAliases will create shell aliases and fmt.Println them -func CreateShellAliases(data []string, username string, config config.Config) { +func CreateShellAliases(data []string, username string, config config.Config, debug bool) { + if debug { + defer utils.LogElapsedTime("Create Shell Aliases") + } for _, i := range data { splitStrings := strings.Split(i, " ") hostname := splitStrings[0] @@ -63,8 +67,9 @@ func CreateShellAliases(data []string, username string, config config.Config) { remoteUser = user } } - - if useJump { + if debug { + fmt.Println("Disabled Output due to Debug Mode") + } else if useJump { fmt.Printf("alias %v=\\'%v%v%v %v@%v \"%v %v %v %v %v\"'\n", host, message, prerac, hop, username, jump, rac, racOpts, remoteUser, fqdn, sudo) } else { fmt.Printf("alias %v=\\'%v %v %v %v %v %v\n", host, message, rac, racOpts, remoteUser, fqdn, sudo)