Skip to content

Commit 6dfc82e

Browse files
TMHSDigitalclaude
andcommitted
refactor(cli): move per-run state into a session struct (#158)
runWith is now 60 lines: its phases (parse, configure, loadInputs, openOutputs, scanAll, finish) are methods on a session that holds the per-run state, emitResult is a method, and the per-target loop body is scanOneTarget. saveResumeState, emitRemoved, buildSummary, scanTarget and runPermutationPass take the session instead of 6 to 13 positional parameters; no function in the main package takes more than 5. cliFlags now holds only parsed flag values. Derived state (attempts, record types, excludes, resolver pool, deadline, stdin, defaults) moves to runtimeInputs, and each pass over a target is a scanPass, so the permutation pass no longer copies and mutates cliFlags. No behaviour change. Fixes #158 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LpkeXSPwrzd7ZCuX3no7gD
1 parent 4183518 commit 6dfc82e

11 files changed

Lines changed: 844 additions & 664 deletions

‎docs/ARCHITECTURE.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ Every package under `internal/` and `pkg/`, summarized from its `// Package` com
4444
Files, by role:
4545

4646
```
47-
main.go - CLI entry point: run/runWith, flag parsing, -dL target loop, exit codes, -tui dispatch
47+
main.go - CLI entry point: run, flag parsing and validation, scanTarget, exit codes
48+
main_session.go - runWith and the session: per-run state, the -dL target loop, -tui dispatch
4849
main_completion.go - completion and man subcommands
4950
main_config.go - config file and SUBENUM_* environment defaults, -print-config
5051
main_ct.go - -ct: Certificate Transparency names as extra candidates
@@ -96,7 +97,7 @@ tools/wordlist-gen.go - Standalone wordlist generator
9697
### 2.1. Argument Parsing (`main.go`, `internal/validate`)
9798

9899
* **Purpose**: This component is responsible for processing the command-line arguments provided by the user when `subenum` is executed. It extracts the target domain (or a `-dL` domain list), the wordlist path, and every scan, output, and tuning option.
99-
* **Implementation**: `run()` only calls `runWith(runArgs)`, which takes the arguments, stdin, stdout and stderr as injected values so tests can drive the whole CLI in-process. `runWith` first handles the `completion` and `man` subcommands and `-resume`, then builds a `flag.FlagSet` with `parseFlagsWith`, which binds every flag into a `cliFlags` struct and applies config-file and environment defaults (see section 5). The standard `flag` package stops at the first non-flag argument, so `parseInterspersed` re-parses around each positional; flags written after the domain are honored, and everything after a `--` terminator is positional. `runWith` then:
100+
* **Implementation**: `run()` only calls `runWith(runArgs)`, which takes the arguments, stdin, stdout and stderr as injected values so tests can drive the whole CLI in-process. Per-run state lives in a `session` (`main_session.go`) whose methods are the run's phases: `parse`, `configure`, `loadInputs`, `openOutputs`, `scanAll` (which calls `scanOneTarget` per target) and `finish`. `cliFlags` holds only parsed flag values; what the run derives from them (attempts, record types, excludes, the resolver pool, the `-max-duration` deadline) is in `runtimeInputs`, and each pass over a target is a `scanPass`. `runWith` first handles the `completion` and `man` subcommands and `-resume`, then builds a `flag.FlagSet` with `parseFlagsWith`, which binds every flag into a `cliFlags` struct and applies config-file and environment defaults (see section 5). The standard `flag` package stops at the first non-flag argument, so `parseInterspersed` re-parses around each positional; flags written after the domain are honored, and everything after a `--` terminator is positional. `runWith` then:
100101
* handles `-tui` (launches `tui.Start`, ignoring other flags), `-print-config` and `-version` first;
101102
* parses `-format` (`output.ParseFormat`), `-type` (`dns.ParseTypes`), and merges `-attempts` with the deprecated `-retries` (`effectiveAttempts`);
102103
* calls `validateFlags`, which checks that `-w` and a target are present, that a positional domain and `-dL` are not both given, and that `-w` and `-dL` do not both read stdin. Numeric ranges and the resolver address are checked by `scan.Options.Validate`, the same validator the TUI uses. The positional domain is canonicalized with `validate.NormalizeDomain`.

‎docs/DEVELOPER_GUIDE.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ subenum/
160160
├── .gitignore
161161
├── .golangci.yml # Linter configuration (golangci-lint v2)
162162
├── .goreleaser.yaml # Release archives, completions, man page
163-
├── main.go # CLI entry point: run/runWith, flag parsing, -dL loop, exit codes
163+
├── main.go # CLI entry point: run, flag parsing and validation, exit codes
164+
├── main_session.go # runWith and the per-run session: the -dL target loop
164165
├── main_completion.go # completion and man subcommands
165166
├── main_config.go # Config file and SUBENUM_* environment defaults, -print-config
166167
├── main_ct.go # -ct: Certificate Transparency names as candidates

0 commit comments

Comments
 (0)