Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

base-cli

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base-cli

Plugin for base-methods that maps built-in methods to CLI args (also supports methods from a few plugins, like 'base-store', 'base-options' and 'base-data'.

  • 0.4.23
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

base-cli NPM version Build Status

Plugin for base-methods that maps built-in methods to CLI args (also supports methods from a few plugins, like 'base-store', 'base-options' and 'base-data'.

You might also be interested in base-config.

Install

Install with npm:

$ npm install base-cli --save

Adds a cli method to base for mapping parsed command line arguments existing base methods or custom functions.

The goal is to simplify the process of settings up command line logic for your base application.

Usage

var cli = require('base-cli');
var Base = require('base');
var app = new Base();

// register the plugin
app.use(cli());

API

This adds a cli object to base with the following (chainable) methods (base.cli.*):

  • .map() - .map: add mappings from command line flags/options to custom functions or base methods
  • .alias() - .alias: similar to map but creates simple aliases. For example, alias('show', 'get') would invoke the .get() method when --show is passed on the command line
  • .process() - .process: once all mappings are defined, pass argv to .process() to iterate over the mappings, passing argv as context.

Example

var argv = require('minimist')(process.argv.slice(2));
var expand = require('expand-args');
var cli = require('base-cli');
var Base = require('base');

var 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);
  })

app.cli.process(expand(argv), function(err) {
  if (err) throw err;
});

// command line args:
//   
//   '--set=a:b --get=a'
//   
// prints:
//   
//   'a'
//   

Commands

The following commands are currently supported.

.ask

Force questions that match the given pattern to be asked. The resulting answer data is merged onto app.cache.data.

After questions are answered:

  • Use app.data('answers') to get answer data.
  • To open the directory where data is persisted, enter --open answers in the command line

Example

# ask all questions
$ --ask
# ask all `author.*` questions
$ --ask 'author.*'
# ask all `*.name` questions (like `project.name` and `author.name`)
$ --ask '*.name*'

.config

Persist a value to a namespaced config object in package.json. For example, if you're using verb, the value would be saved to the verb object.

Params

  • {Object}: app

Example

# display the config
$ --config
# set a boolean for the current project
$ --config=toc
# save the cwd to use for the current project
$ --config=cwd:foo
# save the tasks to run for the current project
$ --config=tasks:readme

.cwd

Set the current working directory.

Example

# set working directory to 'foo'
$ --cwd=foo
# display cwd
$ --cwd

.data

Set data on the app.cache.data object. This is the API-equivalent of calling app.data().

Example

$ --data
# display data object
$ --data=foo
# sets {foo: true}
$ --data=foo:bar
# sets {foo: 'bar'}
$ --data=foo.bar:baz
# sets {foo:{bar: 'baz'}}

.disable

Disable a configuration setting. This is the API-equivalent of calling app.disable('foo'), or app.option('foo', false).

Example

$ --disable=foo
# sets {foo: false}

.emit

Bind console.error to the given event listener, so that when event name is emitted, the event arguments will be output in the console.

Example

# emit errors
$ --emit error
# emit all views as they're created
$ --emit view
# emit only 'pages' as they're created
$ --emit page

.enable

Enable a configuration setting. This is the API-equivalent of calling app.enable('foo'), or app.option('foo', true).

Example

$ --enable=foo
# sets {foo: true}

.global

Persist a value to the global config store by prefixing a command line option with -g or --global.

Params

  • {Object}: app

Example

# save a boolean
$ -g=toc # saves `{ toc: true }` to global defaults
# save the cwd to use as a global default
$ -g=cwd:foo
# save the tasks to run by default
$ -g=tasks:readme

.init

Ask initialization questions and persist answer data to the global config store.

Example

$ --init

.open

Open a directory, or open a file in the default application associated with the file type.

Example

# Open the directory where answer data is persisted
$ --open answers
# Open the directory where store data is persisted
$ --open store

.option

Set options on the app.options object. This is the API-equivalent of calling app.option(). You may also use the plural --options flag for identical behavior.

Example

$ --option=foo
# sets {foo: true}
$ --option=foo:bar
# sets {foo: 'bar'}
$ --option=foo.bar:baz
# sets {foo:{bar: 'baz'}}

.options

Set in-memory options on the app.options object. This is the API-equivalent of calling app.option(). You may also use the singular --option flag for identical behavior.

To display currently defined options, pass the --options flag with no value.

Example

$ --options=foo
# sets {foo: true}
$ --options=foo:bar
# sets {foo: 'bar'}
$ --options=foo.bar:baz
# sets {foo:{bar: 'baz'}}

.save

Persist a value to the global config store by prefixing a command line option with --save or -s.

Params

  • {Object}: app

Example

# save a boolean
$ --save=toc # saves `{ toc: true }` to global config
# save the cwd to use as a global default
$ --save=cwd:foo
# save the tasks to run by default
$ --save=tasks:readme

.tasks

Alias for --tasks. Run the given generators and tasks. This flag is unnecessary when used with base-runner.

Example

# run task "foo"
$ app --task foo
#=> {task: ['foo']}
# run generator "foo", task "bar"
$ app --task foo:bar
#=> {task: ['foo:bar']}

.tasks

Run the given generators and tasks. This flag is unnecessary when used with base-runner.

Example

# run task 'foo'
$ app --tasks foo
# => {task: ['foo']}
# run generator 'foo', task 'bar'
$ app --tasks foo:bar
# => {task: ['foo:bar']}

.show

Returns true if val is true or is an object with show: true

Params

  • val {String}
  • returns {Boolean}

Other useful base plugins:

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with verb:

$ npm install verb && npm run docs

Or, if verb is installed globally:

$ verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016 Jon Schlinkert Released under the MIT license.


This file was generated by verb, v0.9.0, on March 06, 2016.

Keywords

FAQs

Package last updated on 07 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc