Package Exports
- base-cli
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (base-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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'.
You might also be interested in base-config.
Install
Install with npm:
$ npm i 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 orbase
methods.alias()
- .alias: similar tomap
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, passargv
to.process()
to iterate over the mappings, passingargv
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'
//
CLI
--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*"
--cli
Set the current working directory.
Example
$ --cwd=foo
--data
Set data on the app.cache.data
object. This is the API-equivalent of calling app.data()
.
Example
$ --data=foo
# sets {foo: true}
$ --data=foo:bar
# sets {foo: 'bar'}
$ --data=foo.bar:baz
# sets {foo:{bar: 'baz'}}
--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
--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'}}
--tasks
Run the given generators and tasks. This flag is unnecessary when used with [base-runner][].
Example
$ app --tasks foo
# {tasks: ['foo']}
# Runs task "foo"
$ app --tasks foo:bar
# {tasks: ['foo:bar']}
# Runs generator "foo", task "bar"
TODO
- implement
--init
- implement
--config
- implement
--verbose
- implement short flags. do this last
Related projects
Other useful base plugins:
- base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
- base-config: base-methods plugin that adds a
config
method for mapping declarative configuration values to other 'base'… more | homepage - base-data: adds a
data
method to base-methods. | homepage - base-generators: Adds project-generator support to your
base
application. | homepage - base-plugins: Upgrade's plugin support in base-methods to allow plugins to be called any time after init. | homepage
- base-task: base plugin that provides a very thin wrapper around https://github.com/doowb/composer for adding task methods to… more | homepage
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Jon Schlinkert
License
Copyright © 2016 Jon Schlinkert Released under the MIT license.
This file was generated by verb, v0.9.0, on February 09, 2016.