Base CLI Process

raw JSON →
0.1.19 verified Thu Apr 23 auth: no javascript abandoned

base-cli-process is a utility package designed to normalize command-line arguments (`argv`) for applications built on the `base` framework. It functions as a `base` plugin, pre-processing the input object with `base-cli-schema` before invoking the `.process()` method from `base-cli`. This package, currently at version 0.1.19, helps structure and standardize CLI input, offering commands for configuration management (`--config`), current working directory (`--cwd`), data definition (`--data`), option setting (`--option`), and plugin loading (`--plugins`). It is part of an older ecosystem and has not seen recent development. Given its low version number and lack of recent updates, it operates under a pre-1.0 development model where API stability is not guaranteed across minor versions.

error TypeError: app.cli.process is not a function
cause The `base-cli-process` plugin was not correctly registered with the `base` application instance, or the `base-cli` plugin (which adds the `.cli` property) was not used.
fix
Ensure app.use(cli()) is called *after* initializing app = new Base(). Also, verify that base-cli is installed and registered if it provides the .cli property directly to your base instance.
error Error [ERR_REQUIRE_ESM]: require() of ES module not supported
cause Attempting to `require()` `base-cli-process` in a JavaScript environment configured for pure ESM, which does not support synchronous `require` for ESM modules.
fix
This package is CommonJS. If you must use it in an ESM project, consider using a build tool that handles CJS-to-ESM conversion, or if running Node.js, wrap the import in an async import() call (though direct require is usually the issue here).
breaking The package `base-cli-process` is unmaintained and has not seen updates since at least 2017. It depends on an older `base` ecosystem, and its API is subject to change without strict semantic versioning due to being pre-1.0.
fix Consider migrating to a modern, actively maintained CLI parsing library. If continued use is necessary, pin to the exact version and be aware of potential breaking changes if upstream 'base' packages are updated.
gotcha This package is exclusively CommonJS (`require`) and will not work directly in a pure ECMAScript Modules (ESM) environment without transpilation or specific loader configurations (e.g., dual packages, top-level await imports, or tools like `esbuild`/`webpack`).
fix Ensure your project is configured for CommonJS, or use tools to transpile/bundle if integrating into an ESM project. For new projects, prefer ESM-first alternatives.
gotcha The functionality of `base-cli-process` relies heavily on `base-cli` and `base-cli-schema`. Misconfigurations or outdated versions of these peer/runtime dependencies can lead to unexpected behavior or errors during CLI processing.
fix Always install `base`, `base-cli`, and `base-cli-schema` alongside `base-cli-process`. Refer to their respective documentations for compatibility and usage.
npm install base-cli-process
yarn add base-cli-process
pnpm add base-cli-process

Demonstrates how to initialize a `base` application, register `base-cli-process` as a plugin, and then simulate processing command-line arguments to affect `app.options` and `app.config`.

const Base = require('base');
const cli = require('base-cli-process');

// A mock package.json content for demonstration
const pkg = {
  name: 'my-cli-app',
  version: '1.0.0',
  description: 'A simple CLI application',
  scripts: {
    test: 'echo \"Error: no test specified\" && exit 1'
  },
  config: {
    myApp: {
      defaultSetting: true
    }
  }
};

const app = new Base();
// Register the base-cli-process plugin
app.use(cli());

// Simulate a CLI call with some arguments
// For example, running `node app.js --config=myApp.newSetting:value --data=user:guest --help`
const simulatedArgv = {
  config: 'myApp.newSetting:value',
  data: 'user:guest',
  help: true,
  _: [] // minimist usually adds an empty array for non-flag args
};

console.log('--- Before CLI processing ---');
console.log('App options:', app.options);
console.log('App config:', app.config);

// Process the simulated CLI arguments
app.cli.process(simulatedArgv, function(err) {
  if (err) {
    console.error('CLI processing error:', err);
    return;
  }
  console.log('\n--- After CLI processing ---');
  console.log('App options after processing:', app.options);
  console.log('App config after processing:', app.config);
  if (app.cache.get && app.cache.get.help) {
    console.log('Help was requested!');
  }
  console.log('Simulated command-line arguments processed successfully.');
});