UNPKG

base-cli-process

Version:

Normalizers for common argv commands handled by the base-cli plugin. Also pre-processes the given object with base-cli-schema before calling `.process()`

48 lines (40 loc) 871 B
'use strict'; var debug = require('../debug'); var utils = require('../utils'); /** * Define data to be used for rendering templates. * * ```sh * $ app --data=foo:bar * # {foo: 'bar'} * * $ app --data=foo.bar:baz * # {foo: {bar: 'baz'}} * * $ app --data=foo:bar,baz * # {foo: ['bar', 'baz']}} * ``` * @name data * @api public */ module.exports = function(app, base) { return function(val, key, config, next) { debug.field(key, val); if (utils.show(val)) { console.log(utils.formatValue(app.cache.data)); next(); return; } if (typeof app.data === 'function') { app.data(val); } else { for (var prop in val) { app.emit('data', prop, val[prop]); } app.cache.data = utils.merge({}, app.cache.data, val); val = app.cache.data; } config[key] = val; next(); }; };