{"id":16946,"library":"anypoint-cli-command","title":"Anypoint CLI Command Library","description":"The `@mulesoft/anypoint-cli-command` package provides the foundational `Core` class for developing custom commands within the Anypoint CLI version 4 and later ecosystem. It extends `@oclif/core`, inheriting its robust command-line interface framework while adding Anypoint-specific functionalities. Developers leverage this library to gain convenient access to common CLI parameters, a standardized logging mechanism, output formatting utilities, and support for Anypoint platform features like scratch orgs. The current stable version, 1.6.8, is closely aligned with the Anypoint CLI's development cycle, receiving updates as part of the broader toolset's evolution. Its key differentiator is the deep integration with Anypoint platform concepts, streamlining the creation of purpose-built Anypoint CLI extensions.","status":"active","version":"1.6.8","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","anypoint-cli","typescript"],"install":[{"cmd":"npm install anypoint-cli-command","lang":"bash","label":"npm"},{"cmd":"yarn add anypoint-cli-command","lang":"bash","label":"yarn"},{"cmd":"pnpm add anypoint-cli-command","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"The Core class directly extends Command from @oclif/core, making it a fundamental peer dependency.","package":"@oclif/core","optional":false},{"reason":"This library is designed for use exclusively with Anypoint CLI version 4.0.0 or later; it's a runtime environment dependency.","package":"@mulesoft/anypoint-cli-v4","optional":false}],"imports":[{"note":"Primarily used as an ES module for extending base CLI commands. Node.js >=16.0.0 is required.","wrong":"const { Core } = require('@mulesoft/anypoint-cli-command');","symbol":"Core","correct":"import { Core } from '@mulesoft/anypoint-cli-command';"},{"note":"While extending 'Core' from this package, you will frequently need to import 'Command' and 'Flags' directly from '@oclif/core' for defining your CLI's structure and arguments.","symbol":"Command","correct":"import { Command } from '@oclif/core';"},{"note":"Flags are part of the underlying oclif framework and are essential for defining command-line arguments and options for commands built with this library.","symbol":"Flags","correct":"import { Flags } from '@oclif/core';"}],"quickstart":{"code":"import { Command, Flags } from '@oclif/core';\nimport { Core } from '@mulesoft/anypoint-cli-command';\n\ninterface MyCommandFlags {\n  name: string;\n  force: boolean;\n}\n\nexport default class MyHelloCommand extends Core<typeof MyHelloCommand> {\n  static description = 'Say hello to a specified name using Anypoint CLI command base.';\n\n  static examples = [\n    '<%= config.bin %> <%= command.id %> --name Alice',\n    '<%= config.bin %> <%= command.id %> -f'\n  ];\n\n  static flags = {\n    name: Flags.string({ char: 'n', description: 'Name to greet.', required: false }),\n    force: Flags.boolean({ char: 'f', description: 'Force a greeting even if no name is provided.', default: false }),\n  };\n\n  public async run(): Promise<void> {\n    const { flags } = await this.parse(MyHelloCommand);\n    const { name, force } = flags;\n\n    if (force) {\n      this.log('Forcing greeting operation...');\n    }\n\n    if (name) {\n      this.log(`Hello, ${name} from your Anypoint CLI Command!`);\n    } else if (force) {\n      this.log('Hello, anonymous user (forced greeting)!');\n    } else {\n      this.error('Please provide a name or use the --force flag.');\n    }\n\n    this.logger.info(`MyHelloCommand executed with name: ${name ?? 'N/A'}, force: ${force}`);\n    this.exit(0);\n  }\n}\n","lang":"typescript","description":"Demonstrates creating a new CLI command by extending the `Core` class, parsing flags, and using the built-in logger."},"warnings":[{"fix":"Ensure your installed Anypoint CLI version is 4.0.0 or higher by running `anypoint-cli-v4 --version` and updating if necessary.","message":"This library is strictly compatible only with Anypoint CLI version 4.0.0 or later. Using it with older versions of Anypoint CLI will lead to runtime errors.","severity":"breaking","affected_versions":"<4.0.0"},{"fix":"Rely on the public GitHub repository's README for essential usage information or consult external oclif documentation if specific Anypoint CLI library docs are missing.","message":"The documentation references an internal Confluence link ('How to develop a plug-in'). This resource is not publicly accessible and may be outdated, leading to dead links or inaccessible information for external developers.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update your Node.js environment to version 16.0.0 or later using a tool like nvm or your preferred package manager.","message":"This package requires Node.js version 16.0.0 or higher. Running it with older Node.js versions may cause unexpected behavior or failures due to modern JavaScript syntax and API usage.","severity":"gotcha","affected_versions":"<16.0.0"},{"fix":"Consult the official `@oclif/core` documentation for best practices and advanced usage, as this package primarily adds Anypoint-specific wrappers.","message":"The `Core` class extends `@oclif/core`. Developers must be familiar with oclif's command structure, flag definitions, and parsing mechanisms to effectively use this library.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Upgrade your Anypoint CLI to version 4.0.0 or later: `npm update -g @mulesoft/anypoint-cli-v4` or reinstall with the latest version.","cause":"Attempting to use a command built with this library with an older version of Anypoint CLI.","error":"Error: You are attempting to use a command library that requires Anypoint CLI v4.0.0 or later. Your current version is X."},{"fix":"Ensure both `@mulesoft/anypoint-cli-command` and `@oclif/core` are installed in your project: `npm install @mulesoft/anypoint-cli-command @oclif/core` and that imports are correct.","cause":"The base `Core` class from `@mulesoft/anypoint-cli-command` or `Command` from `@oclif/core` was not properly imported or installed.","error":"TypeError: Class extends value undefined is not a constructor or null"},{"fix":"Install the package: `npm install @mulesoft/anypoint-cli-command` (and `@oclif/core`). If using TypeScript, ensure `tsconfig.json` includes `\"moduleResolution\": \"node\"` or appropriate settings.","cause":"The package `@mulesoft/anypoint-cli-command` is not installed or the TypeScript configuration is incorrect.","error":"Error: Cannot find module '@mulesoft/anypoint-cli-command' or its corresponding type declarations."}],"ecosystem":"npm","meta_description":null}