Skip to content

Commit b39fdc0

Browse files
TMHSDigitalclaude
andcommitted
fix(cli): report a missing domain before reading -exclude-file
Domain-argument checks move to validateArgs, which runs before any input file is read, so `subenum -exclude-file missing.txt` says the domain is missing instead of failing on the file. The wordlist-gen part of #120 is in PR #133. Refs #120 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d98b0e1 commit b39fdc0

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎main.go‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,20 +271,29 @@ func endsWithTerminator(fs *flag.FlagSet, consumed []string) bool {
271271
return false // "--" was the value of the preceding flag
272272
}
273273

274-
func validateFlags(f cliFlags, positionals []string, fs *flag.FlagSet, out *output.Writer, maxAttempts int) (string, bool) {
274+
// validateArgs checks the domain arguments, before any input file is read,
275+
// so a missing domain is reported first (#120).
276+
func validateArgs(f cliFlags, positionals []string, fs *flag.FlagSet, out *output.Writer) bool {
275277
if len(positionals) == 0 && f.domainList == "" {
276278
// Say what is missing before the full flag list (#58).
277279
out.Error("missing <domain> (or -dL <domains_file>)")
278280
fs.SetOutput(os.Stderr)
279281
fs.Usage()
280-
return "", false
282+
return false
281283
}
282284
if f.domainList != "" && len(positionals) > 0 {
283285
out.Error("use either a <domain> argument or -dL, not both")
284-
return "", false
286+
return false
285287
}
286288
if len(positionals) > 1 {
287289
out.Error("expected exactly one domain, got %d arguments: %s (use -dL for several)", len(positionals), strings.Join(positionals, " "))
290+
return false
291+
}
292+
return true
293+
}
294+
295+
func validateFlags(f cliFlags, positionals []string, fs *flag.FlagSet, out *output.Writer, maxAttempts int) (string, bool) {
296+
if !validateArgs(f, positionals, fs, out) {
288297
return "", false
289298
}
290299
if f.wordlistFile == wordlist.Stdin && f.domainList == wordlist.Stdin {
@@ -593,6 +602,9 @@ func run() (code int) {
593602
return exitUsage
594603
}
595604

605+
if !validateArgs(f, positionals, fs, out) {
606+
return exitUsage
607+
}
596608
excludes, err := loadExcludes(f)
597609
if err != nil {
598610
out.Error("reading -exclude-file: %v", err)

‎main_test.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,16 @@ func TestLoadPrevious(t *testing.T) {
262262
}
263263
}
264264
}
265+
266+
// TestE2EMissingDomainReportedFirst covers #120: a missing domain is the
267+
// error a user sees, not a missing -exclude-file, and no simulation banner
268+
// is printed before it.
269+
func TestE2EMissingDomainReportedFirst(t *testing.T) {
270+
code, out := runCLIMerged(t, "-simulate", "-exclude-file", "no-such-file.txt")
271+
if code != exitUsage || !strings.Contains(out, "missing <domain>") || strings.Contains(out, "exclude-file:") || strings.Contains(out, "SIMULATION MODE") {
272+
t.Errorf("exit %d, output:\n%s", code, out)
273+
}
274+
if code, out := runCLIMerged(t, "-r", "no-such-resolvers.txt", "example.com"); code != exitFailure {
275+
t.Errorf("unreadable -r: exit %d, want %d\n%s", code, exitFailure, out)
276+
}
277+
}

0 commit comments

Comments
 (0)