Skip to content

feat(core): CLCommand, the base command of the plugins - #270

Open
pviti wants to merge 2 commits into
monorepofrom
feat/core-base-command
Open

pviti wants to merge 2 commits into
monorepofrom
feat/core-base-command

Conversation

@pviti

@pviti pviti commented Oct 2, 2026

Copy link
Copy Markdown
Member

The code the plugins repeated in their base commands moves into a base command of cli-core, CLCommand. 12 plugins extend it, ahead of the oclif 5 major.

cli-core: CLCommand

  • Base flags. organization, domain and accessToken, the flags the CLI fills in from the current application. organizationFlag(), domainFlag() and accessTokenFlag(options) serve the plugins that change them, e.g. -a in checkout, links, metrics and microstore.
  • init().
    • Plugin update check, skipped with --blind, --silent or --quiet.
    • Application kind check, declared with static applicationKinds.
  • catch(). Quitting an interactive prompt.
  • clientOptions(flags). Organization, domain, access token and user agent for the SDK client. cli-core still doesn't depend on the SDK: the plugin creates the client (commercelayer(this.clientOptions(flags))). The SDK 8 apiVersion (feat!: SDK 8 and provisioning-sdk 3 previews (draft, do not merge) #250) will be added here once, instead of in every plugin.
  • handleApiError(error, { resource, id, idLabel, flags }). 401 with the login suggestion, 404 naming the resource, any other error as the API returned it.
  • @oclif/core becomes a peer dependency, so the base command extends the plugin's own Command class (cli-ux already does the same).

Plugins

  • Migrated: checkout, cleanups, exports, imports, links, metrics, microstore, orders, resources, tags, triggers and webhooks. What is specific to a plugin stays in its base command: catch overrides, checkout/microstore/metrics token checks, the triggers error parsing, query flags.
  • Not migrated: provisioning, seeder and token. They don't share this base (provisioning API, flags of their own).
  • Size: about 600 lines fewer in the plugins.

Behaviour

  • Unchanged.
    • Command surfaces: I compared the oclif manifests of the 15 plugins before and after, every command, flag, arg and their properties. The only difference is the new applicationKinds property in the tags manifest.
    • Error output: real 401s from the API, triggered with a fake token, give identical output before and after for tags, webhooks, imports, exports and orders.
  • Changed.
    • The update check is skipped in blind/silent/quiet mode in every plugin, not only in some.
    • cleanups: API errors said "exports" instead of "cleanups" (copy-paste).
    • resources:count tested a --doc flag it doesn't have, which was always undefined. The stricter flag typing showed it.
  • An oclif quirk: oclif's cacheCommand collects static properties only up to the first class that has none. Base commands left with no static property keep an explicit static baseFlags = { ...CLCommand.baseFlags }, otherwise the manifest loses the base flags and strict.

Tests

  • cli-core: 8 new CLCommand tests (94 in total).
  • All plugin suites pass (unchanged).
  • release:try with all 15 plugins: install, plugins, help of several commands, application kind refusal, real 401 handling.
  • lint, check-packages, labels --check, type checks.
  • cli: the usual 2 tests that need the CI credentials fail locally.

🤖 Generated with Claude Code

pviti and others added 2 commits October 2, 2026 16:16
What the plugins that call the Core API repeated in their own base
command, in one place:

- the organization, domain and access token flags the CLI fills in from
  the current application (organizationFlag, domainFlag, accessTokenFlag
  for the plugins that change them);
- the plugin update check, skipped with --blind, --silent or --quiet;
- the application kind check (static applicationKinds);
- quitting an interactive prompt;
- clientOptions(), the options of the SDK client: cli-core stays
  independent of the SDK, the plugin creates the client;
- handleApiError(): the 401 (login suggestion), 404 (missing resource)
  and other API errors.

@oclif/core becomes a peer dependency, so the base command extends the
plugin's own Command class.

BREAKING CHANGE: @oclif/core is a peer dependency of cli-core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
checkout, cleanups, exports, imports, links, metrics, microstore,
orders, resources, tags, triggers and webhooks extend the base command
of cli-core instead of repeating its flags, init, application check,
client options and API errors; what is specific to a plugin stays in
its base command. The command surfaces are unchanged (oclif manifests
compared before and after).

Also:
- the update check is skipped with --blind, --silent or --quiet in all
  of them, not only in some;
- cleanups: the API errors named exports instead of cleanups;
- resources:count tested a --doc flag it doesn't have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant