Skip to content

Commit 852c799

Browse files
author
nova-loop
committed
fix(config): print the effective attempts value in -print-config (#153)
1 parent 3139c44 commit 852c799

4 files changed

Lines changed: 73 additions & 6 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- The scan engine always ends with exactly one done event, marked `Stopped` when the scan ended before testing any candidate (out of scope, recursion ceiling, failed preflight or wildcard check, a wildcard zone without `-force`, or Ctrl+C during those checks), so the CLI, the TUI and `pkg/subenum` handle one shape of ending instead of a channel that sometimes closes without one. `pkg/subenum`'s `Event` gains `Stopped`, and a stopped scan's `Stats` now include the queries its checks sent (#99).
1313

1414
### Fixed
15+
- `-print-config` shows the `attempts` value a scan actually uses: `1` by default instead of the raw `0` sentinel, and the `-retries` value (marked `from retries`) when that is what wins (#153).
1516
- `tools/wordlist-gen` parses flags that appear after a positional the same way `subenum` does, instead of silently ignoring both: a leftover argument is now a usage error (2) that points at `-domain`, and an invalid `-combine` value or an empty `-o` exits 2 instead of 1 (#120).
1617

1718
## [0.9.0] - 2026-10-06

‎main.go‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,17 @@ func scanTarget(ctx context.Context, f cliFlags, domain string, entries []string
11701170
// an env value over the config file); both at the same level is an error
11711171
// (#116).
11721172
func resolveAttempts(attempts, retries int, attemptsSrc, retriesSrc string) (int, error) {
1173+
n, fromRetries, err := effectiveAttempts(attempts, retries, attemptsSrc, retriesSrc)
1174+
if err == nil && fromRetries {
1175+
fmt.Fprintln(os.Stderr, "Warning: -retries is deprecated, use -attempts instead")
1176+
}
1177+
return n, err
1178+
}
1179+
1180+
// effectiveAttempts is resolveAttempts without the deprecation warning. It
1181+
// also reports whether the value came from -retries, so -print-config can
1182+
// show the value the scanner will actually use.
1183+
func effectiveAttempts(attempts, retries int, attemptsSrc, retriesSrc string) (n int, fromRetries bool, err error) {
11731184
attemptsSet := attempts != 0
11741185
retriesSet := retries != 0
11751186
if attemptsSet && retriesSet {
@@ -1183,13 +1194,12 @@ func resolveAttempts(attempts, retries int, attemptsSrc, retriesSrc string) (int
11831194

11841195
switch {
11851196
case attemptsSet && retriesSet:
1186-
return 0, fmt.Errorf("cannot use both -attempts and -retries; use -attempts only")
1197+
return 0, false, fmt.Errorf("cannot use both -attempts and -retries; use -attempts only")
11871198
case retriesSet:
1188-
fmt.Fprintln(os.Stderr, "Warning: -retries is deprecated, use -attempts instead")
1189-
return retries, nil
1199+
return retries, true, nil
11901200
case attemptsSet:
1191-
return attempts, nil
1201+
return attempts, false, nil
11921202
default:
1193-
return 1, nil
1203+
return 1, false, nil
11941204
}
11951205
}

‎main_config.go‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"path/filepath"
1313
"sort"
14+
"strconv"
1415
"strings"
1516
)
1617

@@ -212,10 +213,38 @@ func (d *defaultsLoader) printConfig(w io.Writer, fset *flag.FlagSet) {
212213
if given[fl.Name] {
213214
source = sourceFlag
214215
}
215-
_, _ = fmt.Fprintf(w, "%-14s = %-24q (%s)\n", fl.Name, fl.Value.String(), source)
216+
value := fl.Value.String()
217+
if fl.Name == "attempts" {
218+
value, source = d.effectiveAttemptsSetting(fset, value, source)
219+
}
220+
_, _ = fmt.Fprintf(w, "%-14s = %-24q (%s)\n", fl.Name, value, source)
216221
})
217222
}
218223

224+
// effectiveAttemptsSetting resolves -attempts the way a scan does: 0 means
225+
// "unset", so the effective value is 1 or whatever -retries supplies. When
226+
// the two conflict the raw value is kept, since a scan would refuse to run.
227+
func (d *defaultsLoader) effectiveAttemptsSetting(fset *flag.FlagSet, value, source string) (string, string) {
228+
retriesFlag := fset.Lookup("retries")
229+
if retriesFlag == nil {
230+
return value, source
231+
}
232+
attempts, err1 := strconv.Atoi(value)
233+
retries, err2 := strconv.Atoi(retriesFlag.Value.String())
234+
if err1 != nil || err2 != nil {
235+
return value, source
236+
}
237+
retriesSrc := d.source(fset, "retries")
238+
n, fromRetries, err := effectiveAttempts(attempts, retries, source, retriesSrc)
239+
if err != nil {
240+
return value, source
241+
}
242+
if fromRetries {
243+
source = retriesSrc + ", from retries"
244+
}
245+
return strconv.Itoa(n), source
246+
}
247+
219248
// settings returns the effective value of every setting that came from the
220249
// environment or the config file, keyed by flag name, for the TUI's form.
221250
func (d *defaultsLoader) settings(fs *flag.FlagSet) map[string]string {

‎main_config_test.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,30 @@ func TestFileFlagsAreComplete(t *testing.T) {
214214
}
215215
}
216216
}
217+
218+
// -print-config shows the attempts value a scan will use, not the raw 0
219+
// sentinel (#153).
220+
func TestPrintConfigEffectiveAttempts(t *testing.T) {
221+
for _, tc := range []struct {
222+
args []string
223+
env map[string]string
224+
want string
225+
}{
226+
{nil, nil, `attempts = "1" (default)`},
227+
{[]string{"-attempts", "4"}, nil, `attempts = "4" (flag)`},
228+
{[]string{"-retries", "3"}, nil, `attempts = "3" (flag, from retries)`},
229+
{nil, map[string]string{"SUBENUM_RETRIES": "2"}, `attempts = "2" (env, from retries)`},
230+
{[]string{"-attempts", "5"}, map[string]string{"SUBENUM_RETRIES": "2"}, `attempts = "5" (flag)`},
231+
} {
232+
d := &defaultsLoader{getenv: func(k string) string { return tc.env[k] }}
233+
_, _, fs, err := parseFlagsWith(append(tc.args, "example.com"), d.apply)
234+
if err != nil {
235+
t.Fatal(err)
236+
}
237+
var out bytes.Buffer
238+
d.printConfig(&out, fs)
239+
if !strings.Contains(out.String(), tc.want) {
240+
t.Errorf("%v %v: -print-config lacks %q:\n%s", tc.args, tc.env, tc.want, out.String())
241+
}
242+
}
243+
}

0 commit comments

Comments
 (0)