Skip to content

Commit

Permalink
support quiet (no console output and tidy up.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhadfield committed May 17, 2018
1 parent 7ac22b9 commit 48870d2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
38 changes: 20 additions & 18 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ func checkBodyResponse(pattern vPattern, body io.ReadCloser) (result bool) {

var domainIssues issues

func CheckDomains(path string, configPath string, debug *bool) {
func CheckDomains(path string, configPath *string, debug *bool, quiet *bool) {
var conf Config
if configPath != "" {
conf = readConfig(configPath)
if *configPath != "" {
conf = readConfig(*configPath)
}
file, _ := os.Open(path)
domainScanner := bufio.NewScanner(file)
Expand All @@ -222,26 +222,28 @@ func CheckDomains(path string, configPath string, debug *bool) {

var progress string
for a := 1; a <= numDomains; a++ {
progress = fmt.Sprintf("Processing... %d/%d %s", a, numDomains, domains[a-1])
progress = padToWidth(progress, true)
width, _, _ := terminal.GetSize(0)
if len(progress) == width {
fmt.Printf(progress[0:width-3] + " \r")
} else {
fmt.Print(progress)
if !*quiet {
progress = fmt.Sprintf("Processing... %d/%d %s", a, numDomains, domains[a-1])
progress = padToWidth(progress, true)
width, _, _ := terminal.GetSize(0)
if len(progress) == width {
fmt.Printf(progress[0:width-3] + " \r")
} else {
fmt.Print(progress)
}
}

<-results
}
// clear
fmt.Printf("%s", padToWidth(" ", false))
// get issues summary
pIssues := getIssuesSummary(domainIssues)
if !reflect.DeepEqual(pIssues, processedIssues{}) {
displayIssues(pIssues)
} else {
fmt.Println("\nno issues found.")
if !*quiet {
fmt.Printf("%s", padToWidth(" ", false))
if !reflect.DeepEqual(pIssues, processedIssues{}) {
displayIssues(pIssues)
} else {
fmt.Println("\nno issues found.")
}
}

// send notifications
if conf.Email.Provider != "" {
if *debug {
Expand Down
12 changes: 7 additions & 5 deletions cmd/subtocheck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
var (
domainListPath = kingpin.Flag("domains", "domain list file path").Default("domains.txt").String()
configPath = kingpin.Flag("config", "config file").String()
quiet = kingpin.Flag("quiet", "suppress command line output").Bool()
debug = kingpin.Flag("debug", "enable debug").Bool()
)

Expand Down Expand Up @@ -97,14 +98,15 @@ func main() {
kingpin.Parse()
kingpin.UsageTemplate(usageTemplate)

var err error
if *quiet && *configPath == "" {
fmt.Println("warning: running without console output and without email config ¯\\_(ツ)_/¯")
}

var domainsPath string
domainsPath, err = getDomainListFilePath(*domainListPath)
domainsPath, err := getDomainListFilePath(*domainListPath)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
panic(err)
} else {
subtocheck.CheckDomains(domainsPath, *configPath, debug)
subtocheck.CheckDomains(domainsPath, configPath, debug, quiet)
}
}

0 comments on commit 48870d2

Please sign in to comment.