base-cli

raw JSON →
0.5.0 verified Sat Apr 25 auth: no javascript maintenance

Plugin for base-methods that maps built-in methods to CLI arguments, supporting methods from plugins like base-store, base-options, and base-data. Current stable version: 0.5.0. Release cadence: infrequent, no recent updates. Key differentiators: simplifies setting up command line logic for base applications by adding a cli object with .map(), .alias(), and .process() methods. Alternative: base-config for declarative configuration.

error TypeError: app.cli is undefined
cause Forgetting to call cli() as function or before using app.cli.
fix
Ensure app.use(cli()); is called before accessing app.cli
error Error: base-cli requires base-methods 0.x
cause Using base version 1.x or higher which changed the API.
fix
Downgrade base to 0.x or use a different CLI plugin.
breaking Requires 'base' version 0.x; incompatible with base 1.x.
fix Use base@0.x or fork/update plugin.
deprecated Package is no longer actively maintained; no updates since 2017.
fix Consider migrating to base-config or modern CLI framework.
gotcha cli() must be called as a function, not passed directly to app.use().
fix app.use(cli()) instead of app.use(cli)
gotcha Map callbacks lose context; must use function or arrow to access app.
fix Use app.cli.map('get', (key, val) => app.get(key, val));
npm install base-cli
yarn add base-cli
pnpm add base-cli

Demonstrates registering base-cli plugin, mapping CLI flags to base methods, and processing argv.

const cli = require('base-cli');
const Base = require('base');
const app = new Base();
app.use(cli());

app.cli
  .map('get', function(key, val) {
    app.get(key, val);
  })
  .map('set', function(key, val) {
    app.set(key, val);
  });

const argv = require('minimist')(process.argv.slice(2));
const expand = require('expand-args');
app.cli.process(expand(argv), function(err) {
  if (err) throw err;
});