Base CLI Process
raw JSON →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.
Common errors
error TypeError: app.cli.process is not a function ↓
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 ↓
import() call (though direct require is usually the issue here). Warnings
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. ↓
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`). ↓
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. ↓
Install
npm install base-cli-process yarn add base-cli-process pnpm add base-cli-process Imports
- cli
const cli = require('base-cli-process'); - Base
const Base = require('base'); - pluginUsage
app.use(cli());
Quickstart
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.');
});