-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Enhancement Description
Make CLI validation fail-fast by moving checks to PreRunE/MarkFlagRequired and centralizing shared validators.
Background
Commands currently validate inputs inside RunE after expensive work (service init, config I/O, network checks). This causes multi-second delays before reporting invalid input and proliferates duplicated validation logic.
Scope
Move validations from RunE to PreRunE across commands
Files: cmd/devnet-builder/commands/, cmd/dvb/
Use declarative required flags
Files: cmd/devnet-builder/commands/, cmd/dvb/
- Replace manual “empty string” checks with MarkFlagRequired where applicable
Centralize shared validation helpers
Files: internal/cmd/validation/** (new package)
- Mode validation
- Validator count validation
- Network validation
- Daemon requirement checks (promote to parent PersistentPreRunE where possible)
Non-Goals
- Changing command behavior beyond validation timing
- Introducing new flags or breaking existing CLI interface
- Large refactors of application service initialization
Risks and Open Questions
- Some validations currently depend on config load; ensure cheap validation still possible (or fast-path load)
- Cobra hook ordering must be consistent for subcommands and persistent hooks
- Error message consistency needs alignment across commands
Validation Plan
Unit and Integration Checks
- go test ./... for command packages and validation package
- Unit tests for internal/cmd/validation helpers
- Ensure commands fail before service initialization for invalid inputs (test with fakes)
End-to-End Checks
- Manual smoke: run invalid-flag combinations and confirm errors return immediately
- Smoke deploy/upgrade/provision still work with correct inputs
Evidence Required in Issue Updates
- Timing evidence (command logs or simple benchmarks) showing <100ms failure on invalid input
- Diff of removed manual validation patterns (examples)
- Example error outputs showing consistent messages
Acceptance Criteria
- Invalid inputs fail before service initialization
- Required flags use MarkFlagRequired where appropriate
- Cross-flag validation is in PreRunE
- Manual validation occurrences reduced significantly (target: < 50)
- No command initializes services before failing validation
Deliverables
- PR migrating validations to PreRunE and introducing shared validation package
- Documentation update (if needed) for validation behavior and error messages
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels