Conversation
Remove --interactive from global flags. Ensure it is supported on the command that implement it and update prerun check to require the correct flags
There was a problem hiding this comment.
Pull request overview
This PR refactors CLI flag validation by removing MarkPersistentFlagRequired() usage and moving “required flag” enforcement to per-command PreRun logic, adding richer Cobra validations (one-required / required-together / mutually-exclusive) and enabling interactive flows on select commands.
Changes:
- Replaced persistent required flags with per-subcommand
PreRunrequirements across multiple command trees (tenant/user/project/gateway/agent/node/nexus/rc). - Introduced interactive-mode flag gating for
tenant configure-dns,tenant verify-dns, andgateway install. - Simplified some validations by using Cobra’s flag-group helpers instead of manual
os.Exit()validation blocks.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
src/cmd/root.go |
Removes global --interactive persistent flag from root. |
src/cmd/agent.go |
Adds --swarm-id requirement + batch/single validation via Cobra helpers; adds examples. |
src/cmd/node.go |
Adds --swarm-id/--nexus-id requirements and batch/single validation; adds examples. |
src/cmd/nexus.go |
Makes --swarm-id required across nexus subcommands. |
src/cmd/gateway.go |
Requires --tenant-id on non-interactive gateway commands; adds interactive install mode + examples. |
src/cmd/tenant.go |
Moves list validation into Run; adds interactive DNS flows with flag-group validation. |
src/cmd/project.go |
Requires --tenant-id per subcommand; moves list sort validation into Run. |
src/cmd/user.go |
Requires --tenant-id per subcommand; adjusts list pre-run validation. |
src/cmd/swarm.go |
Replaces manual “name/description required” check with MarkFlagsOneRequired. |
src/cmd/operator.go |
Refactors tenant/swarm branching and moves tenant/swarm flags to persistent flags. |
src/cmd/policy.go |
Minor formatting cleanup; keeps tenant/swarm mutual exclusion logic. |
src/cmd/redundancy_class.go |
Requires --swarm-id per subcommand; updates create validation requirements. |
src/cmd/redundancy_class_recovery.go |
Adds rc-id/swarm-id requirements for recovery subcommands; adjusts persistent flags. |
.gitignore |
Ignores opencode artifacts. |
Comments suppressed due to low confidence (1)
src/cmd/user.go:143
- The invalid sort-key error message lists tenant fields (
id, name, owner_id, ...) but this command’sallowedSortingKeysisid, first_name, last_name, .... This makes the guidance incorrect when users hit the validation error; update the message to match the actual allowed keys.
allowedSortingKeys := []string{"id", "first_name", "last_name", "max_allowed_projects", "created_at", "deleted_at", "tenant_id"}
sort, _ := cmd.Flags().GetString("sort")
if sort != "" && !utils.Contains(allowedSortingKeys, sort) {
fmt.Println("Error: invalid sort key provided, allowed keys are: id, name, owner_id, coupon_id, created_at, deleted_at")
cmd.Usage()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors Cobra flag validation across the CLI by removing MarkPersistentFlagRequired() usage and instead enforcing required flags and flag relationships at the subcommand level (often via PreRun plus Cobra’s MarkFlags* helpers), with additional interactive-mode support on certain commands.
Changes:
- Removed persistent required-flag markings and added per-command required flag validation.
- Introduced/expanded interactive-mode flows for selected commands (e.g., gateway install, tenant DNS).
- Converted some commands to
RunEand replaced severalos.Exit()validation paths with returned errors.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
src/cmd/agent.go |
Adds swarm-id requirement and new flag relationship validation; introduces RunE for list and updates validation style. |
src/cmd/gateway.go |
Improves tenant-id enforcement and interactive install validation; updates list validation to RunE. |
src/cmd/nexus.go |
Adds swarm-id requirement to nexus subcommands and removes persistent required marking. |
src/cmd/node.go |
Adds swarm/nexus requirements and batch vs single-create flag relationships; moves some validation into RunE. |
src/cmd/operator.go |
Changes IAM user scoping to allow either tenant-id or swarm-id instead of globally requiring tenant-id. |
src/cmd/policy.go |
Minor formatting cleanup in flag validation blocks. |
src/cmd/project.go |
Adds tenant-id requirement at subcommand level; changes list to RunE. |
src/cmd/redundancy_class.go |
Adds swarm-id requirement and updates RC create validation requirements. |
src/cmd/redundancy_class_recovery.go |
Moves rc-id requirement to subcommands and adds swarm-id requirement. |
src/cmd/root.go |
Removes root persistent --interactive flag. |
src/cmd/swarm.go |
Uses MarkFlagsOneRequired(name, description) for edit validation instead of manual checks. |
src/cmd/tenant.go |
Converts tenant list to RunE; adds interactive-mode flags/validation to DNS commands. |
src/cmd/user.go |
Adds tenant-id required validation per user subcommand; removes persistent required marking. |
.gitignore |
Ignores opencode-related files/directories. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if err := action.ListGateways(cmd, args); err != nil { | ||
| utils.PrintError(err) | ||
| return err |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Summary
Removes all
MarkPersistentFlagRequired()calls and moves flag requirements to individual commandPreRunfunctions. Improves CLI stability, interactive mode support, and user experience.Changes
12 files modified (+177 insertions, -215 deletions)
Key Improvements
MarkPersistentFlagRequired()- Prevents panics from nil pointer dereferencesgateway install --interactiveno longer requires--tenant-idor--gateway-idMarkFlagsOneRequired(),MarkFlagsRequiredTogether(),MarkFlagsMutuallyExclusive()os.Exit()with graceful returnsFiles Modified
agent.go--swarm-idrequirement, improved batch/individual flag validationgateway.gonexus.go--swarm-idrequirement to all commandsnode.go--swarm-idrequirement, improved batch validationoperator.goproject.go--tenant-idrequirement to all commandsuser.go--tenant-idrequirement to all commandsredundancy_class.go--swarm-idrequirementredundancy_class_recovery.go--swarm-idrequirementtenant.goswarm.gopolicy.goFlag Requirements
Commands Requiring
--swarm-idagent(create, describe, edit, list, remove, status)nexus(create, describe, edit, list, remove, deploy)node(create, describe, edit, list, remove, deploy)rc(create, describe, status, expand, list, recovery start/status)Commands Requiring
--tenant-idgateway(create, describe, edit, install, list, remove)tenant project(all subcommands)tenant user(all subcommands)Commands Supporting Interactive Mode
gateway install- Either--interactiveOR (--tenant-id+--gateway-id)tenant configure-dns- Either--interactiveOR (--tenant-id+--domain)tenant verify-dns- Either--interactiveOR--tenant-idCommands Requiring Either
--tenant-idOR--swarm-idiam user(create, list, remove, describe)Testing
Impact