base-cli-process
Advanced tools
Comparing version 0.1.7 to 0.1.8
24
index.js
@@ -45,10 +45,7 @@ 'use strict'; | ||
var defaults = { | ||
sortArrays: false, | ||
omitEmpty: true, | ||
keys: ['init', 'run', 'toc', 'layout', 'tasks', 'options', 'data', 'plugins', 'related', 'reflinks'] | ||
}; | ||
var defaults = {sortArrays: false, omitEmpty: true}; | ||
var keys = ['get', 'set', 'toc', 'layout', 'options', 'data', 'plugins', 'related', 'reflinks', 'init', 'run', 'tasks']; | ||
var opts = createOpts(app, config, defaults); | ||
var obj = this.schema.normalize(val, opts); | ||
var obj = sortObject(this.schema.normalize(val, opts), keys); | ||
@@ -81,2 +78,17 @@ debug('processing normalized argv', obj); | ||
function sortObject(obj, keys) { | ||
if (Array.isArray(keys) && keys.length) { | ||
keys = utils.arrUnion(keys, Object.keys(obj)); | ||
var len = keys.length, i = -1; | ||
var res = {}; | ||
while (++i < len) { | ||
var key = keys[i]; | ||
if (obj.hasOwnProperty(key)) { | ||
res[key] = obj[key]; | ||
} | ||
} | ||
return res; | ||
} | ||
} | ||
function createOpts(app, config, defaults) { | ||
@@ -83,0 +95,0 @@ if (typeof defaults !== 'undefined') { |
@@ -38,2 +38,44 @@ 'use strict'; | ||
/** | ||
* Ensure the requisite plugins are registered when a command is given, | ||
* otherwise throw an error. | ||
*/ | ||
utils.assertPlugins = function(app, key) { | ||
switch(key) { | ||
case 'pkg': | ||
case 'config': | ||
app.assertPlugin('base-pkg'); | ||
break; | ||
case 'option': | ||
case 'options': | ||
app.assertPlugin('base-option'); | ||
break; | ||
case 'task': | ||
case 'tasks': | ||
app.assertPlugin('base-task'); | ||
break; | ||
case 'helper': | ||
case 'helpers': | ||
case 'asyncHelper': | ||
case 'asyncHelpers': | ||
case 'engine': | ||
case 'engines': | ||
app.assertPlugin('templates'); | ||
break; | ||
case 'plugin': | ||
case 'plugins': | ||
app.assertPlugin('base-pipeline'); | ||
break; | ||
case 'global': | ||
case 'store': | ||
app.assertPlugin('base-store'); | ||
break; | ||
case 'data': { | ||
app.assertPlugin('base-data:cache.data'); | ||
break; | ||
} | ||
} | ||
}; | ||
/** | ||
* Format a value to be displayed in the command line | ||
@@ -40,0 +82,0 @@ */ |
{ | ||
"name": "base-cli-process", | ||
"description": "Normalizers for common argv commands handled by the base-cli plugin. Also pre-processes the given object with base-cli-schema before calling `.process()`", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"homepage": "https://github.com/jonschlinkert/base-cli-process", | ||
@@ -50,2 +50,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"base-pipeline": "^0.2.5", | ||
"base-store": "^0.4.2", | ||
"delete": "^0.3.1", | ||
@@ -62,2 +63,3 @@ "engine-base": "^0.1.2", | ||
"map-schema": "^0.2.3", | ||
"minimist": "^1.2.0", | ||
"mocha": "^2.4.5" | ||
@@ -92,7 +94,7 @@ }, | ||
"base-cli-schema", | ||
"verb", | ||
"templates", | ||
"base-data", | ||
"base-option", | ||
"base-pipeline" | ||
"base-pipeline", | ||
"templates", | ||
"verb" | ||
], | ||
@@ -99,0 +101,0 @@ "lint": { |
@@ -91,2 +91,17 @@ # base-cli-process [](https://www.npmjs.com/package/base-cli-process) [](https://npmjs.org/package/base-cli-process) [](https://travis-ci.org/jonschlinkert/base-cli-process) | ||
### [.del](lib/fields/del.js#L20) | ||
Delete a value from `app`. | ||
**Example** | ||
```json | ||
# delete a value from package.json config (e.g. `verb` object) | ||
$ app --del=config.foo | ||
# delete a value from in-memory options | ||
$ app --del=option.foo | ||
# delete a property from the global config store | ||
$ app --del=global.foo | ||
``` | ||
### [.dest](lib/fields/dest.js#L17) | ||
@@ -116,2 +131,12 @@ | ||
### [.get](lib/fields/get.js#L16) | ||
Get a value from `app` and set it on `app.cache.get` in memory, allowing the value to be re-used by another command, like `--set`. | ||
**Example** | ||
```json | ||
$ app --get=pkg.name | ||
``` | ||
### [.help](lib/fields/help.js#L19) | ||
@@ -177,2 +202,14 @@ | ||
### [.set](lib/fields/set.js#L17) | ||
Set the given value, or a value was previously cached by `--get`. | ||
**Example** | ||
```json | ||
$ app --set=pkg.name:foo | ||
# example: persist `pkg.name` to `store.data.name` | ||
$ app --get=pkg.name --set=store.name | ||
``` | ||
### [.toc](lib/fields/toc.js#L18) | ||
@@ -241,2 +278,2 @@ | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on May 07, 2016._ | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on May 09, 2016._ |
33061
29
983
275
18