Skip to content

Route the shell's built-in commands with Cobra #87

Description

@kanushka

Parent

#85

What to build

Every command the shell owns is routed by Cobra, and the shell's common flags work on all of them. A user can give --context or --output to any shell command, in either position around the subcommand name, and get the same result. wso2 help and wso2 <command> --help describe what actually exists, because the text is generated from the command tree rather than maintained by hand. A misspelled shell command suggests what was probably meant.

Nothing a user does today stops working. An argument the shell does not recognise still resolves as a product namespace and reaches the product module with its arguments verbatim. A flag error still reads in the shell's voice, with recovery guidance and the documented usage exit class, not in Cobra's. Built-in commands still win over any installed namespace, and asking for help still works before anything is installed and without touching the module store.

Flag semantics do not change in this ticket: the built-in command bodies keep their current argument handling behind the new routing, so the existing tests are the regression suite. Command suggestions cover shell commands only for now, and the product namespace path keeps interpreting the output flag itself, both of which are lifted by #86.

The decision is recorded as an ADR: Cobra is adopted for the shell's command UI; the shell links Cobra and pflag only and never the documentation-generation subpackage; passthrough at the namespace boundary stays hand-written pending declared command trees; and argument parsing will read a declared tree from the integrity-checked receipt, never from the unsigned remote catalog. The existing shell command framework research points at that ADR instead of standing as a recommendation against it.

Acceptance criteria

  • --context and --output are declared once on the root and accepted before or after a command name, and a command that cannot act on one refuses it as a typed usage problem rather than accepting and ignoring it
  • -o json, -o=json, --output json, and --output=json are all accepted
  • Help output is generated from the command tree, lists every shell command, and states that product commands come from installed modules
  • A misspelled shell command suggests the closest shell command
  • An unknown flag, a flag missing its argument, and a malformed flag value each report a typed usage problem with recovery guidance and the usage exit class, with a test per kind
  • Cobra prints neither errors nor usage itself; one exit path maps problem category to exit class
  • An unrecognised first argument still resolves as a product namespace, and the module still receives its arguments unparsed
  • Built-in commands still take precedence over a receipt namespace, and the existing test asserting it passes unchanged
  • The existing test asserting an unknown command is a usage problem passes unchanged
  • Help reads no module store and touches no filesystem state
  • A test matrix covers shell flags in both positions around a subcommand name and around a product namespace, including a module's own flag following a leading shell flag
  • One table-driven test asserts both interpreters of the output flag agree on the same argument list
  • A boundaries test asserts the shell binary links Cobra and pflag and not the documentation-generation subpackage
  • The hand-written help implementation is deleted
  • ADR is added, and the shell command framework research carries a status pointer to it

Blocked by

None (can start immediately).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type/ImprovementMarks enhancements or improvements to existing featuresready-for-agentFully specified and ready for implementation by an agent

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions