Skip to content

gatekit-cmd: reusable cobra command/flag gating bindings #36

Open

Description

@leninmehedy

Summary

Extract a reusable gatekit-cmd module: cobra bindings that gate commands and flags by a gatekit feature's maturity, so consumers don't reinvent the glue.

This fits the ecosystem layering:

  • gatekit — core resolution, zero-dependency (no cobra).
  • gatekit-automa — durable execution.
  • gatekit-cmd — cobra command/flag gating (new).

Keeping cobra out of core preserves gatekit's zero-dependency property; gatekit-cmd carries the cobra dependency.

Motivation

solo-weaver built this glue in cmd/cli/commands/common/feature_gate.go (see reference below). It is non-trivial and easy to get subtly wrong — the reusable surface is:

  • Gate a command by maturity — an Alpha command is hidden from --help, a Beta command is labelled [beta], both refuse to run unless opted in; GA always runs. On a command group it gates the whole subtree.
  • Gate a single flag by maturity — for when a stable command gains an unproven flag.
  • Scoped --experimental opt-in + per-feature env var, both readiness-aware (a dormant Alpha, Default:false feature can't be enabled).
  • One gate shared on the command context so the command check and business code resolve the feature identically.
  • Correct cobra wiring: the check lives on PersistentPreRunE (which cobra inherits) — not PreRunE (which it doesn't) — so an inherited persistent flag is gated on subcommands too. This is the easy-to-miss bit.

Proposed API (sketch)

gatekitcmd.GateFeature(cmd, feature)            // gate a command by maturity
gatekitcmd.GateFeatureFlag(cmd, "flag", feature) // gate a single flag

Seams to generalize (decouple from the solo reference)

Coupled in the reference In gatekit-cmd
solo's featuregate.New/Options/Catalog a caller-supplied gate factory (func(overrides) (*FeatureGate, error))
featuregate.ExperimentalReady promote into gatekit core — it is just WithExperimental resolution for one feature
solo's errx/errorx/reasons refusal return a plain error, or take a caller-supplied error formatter (keep it dep-light)
solo's root pre-run chaining chain whatever prev pre-run exists; the caller wires their own root
context key (NewContext/Gate) generic — lives in gatekit-cmd (or core)

Open questions

  • Does ExperimentalReady belong in gatekit core? (Leaning yes.)
  • Module name / repo: gatekit-cmd.
  • How dep-light to keep error formatting — plain error vs. a pluggable formatter.
  • Whether to seed it now (solo as first consumer) or wait for a second consumer.

Reference implementation

solo-weaver cmd/cli/commands/common/feature_gate.go — PR hashgraph/solo-weaver#1482.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions