Skip to content

refactor(cli): use the canonical dispatch pattern for alerts and license#1056

Open
joshrotenberg wants to merge 1 commit into
mainfrom
refactor/1049-canonical-dispatch-pattern
Open

refactor(cli): use the canonical dispatch pattern for alerts and license#1056
joshrotenberg wants to merge 1 commit into
mainfrom
refactor/1049-canonical-dispatch-pattern

Conversation

@joshrotenberg

Copy link
Copy Markdown
Collaborator

Part of #1049 (Phase 3, CODE-09).

Problem

alerts, license and workflow license were the last enterprise command groups using an in-file dispatch pattern:

#[derive(Debug, Subcommand)]
pub enum AlertsCommands { /* ... */ }

impl AlertsCommands {
    pub async fn execute(&self, config: &Config, /* ... */) -> AnyhowResult<()> {
        let conn_manager = ConnectionManager::new(config.clone());
        // match + handler calls, all in the same file
    }
}

Every other group (database, cluster, node, crdb, logs, module, rbac) uses:

pub async fn handle_x_command(
    conn_mgr: &ConnectionManager,
    profile_name: Option<&str>,
    command: &XCommands,
    output_format: OutputFormat,
    query: Option<&str>,
) -> CliResult<()>

with the enum declared separately and the handler bodies in a *_impl.rs module.

Change

  • Moved the three enums into cli/enterprise.rs as EnterpriseAlertsCommands, EnterpriseLicenseCommands and EnterpriseLicenseWorkflowCommands, matching the Enterprise*Commands naming of its neighbours.
  • Added alerts_impl.rs, license_impl.rs and license_workflow_impl.rs holding the handler functions.
  • alerts.rs, license.rs and license_workflow.rs are now dispatch-only, exposing handle_alerts_command, handle_license_command and handle_license_workflow_command.
  • Handlers take &ConnectionManager rather than constructing one from &Config. The workflow handlers, which need the profile list, read it off conn_mgr.config.
  • license_workflow_impl.rs imports calculate_days_remaining and bytes_to_gb from license_impl instead of reaching into super::license from a sibling command module.

Behavior

None intended. The clap attributes, subcommand names, aliases, after_help examples and handler bodies all move verbatim. enterprise alerts --help, enterprise license --help and enterprise workflow license --help render the same command lists as before.

Two things were deliberately left alone:

Checks

cargo fmt --all -- --check, cargo clippy --all-targets -- -D warnings and cargo test all pass locally. cargo doc --no-deps --all-features produces only the two pre-existing warnings in cli/enterprise.rs (module :args and a bare cluster URL), unchanged by this diff.

Follow-up

The "add a command" checklist for AGENTS.md, also listed under #1049 Phase 3, is a separate docs-only change and is not in this PR.

The alerts, license and license workflow command groups were the last
enterprise commands using an in-file `enum + impl X { execute(&Config) }`
dispatch. Every other group (database, cluster, node, crdb, logs, module,
rbac) declares its enum separately and dispatches through a
`handle_x_command(conn_mgr, ...)` free function backed by a `*_impl.rs`
module.

Convert the three outliers to that shape:

- move `AlertsCommands`, `LicenseCommands` and `LicenseWorkflowCommands`
  into cli/enterprise.rs as `EnterpriseAlertsCommands`,
  `EnterpriseLicenseCommands` and `EnterpriseLicenseWorkflowCommands`
- add alerts_impl.rs, license_impl.rs and license_workflow_impl.rs
  holding the handler functions
- take `&ConnectionManager` instead of building one from `&Config`, so
  the workflow handlers read profiles off `conn_mgr.config`
- drop the cross-file `super::license::calculate_days_remaining` reach
  from the workflow handlers in favour of a `super::license_impl` import

No behavior change: the clap attributes, subcommand names, aliases and
help text all move verbatim, and the handler bodies are unchanged.

Part of #1049.
@joshrotenberg
joshrotenberg marked this pull request as ready for review July 25, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant