1 | # base-cli-schema [![NPM version](https://img.shields.io/npm/v/base-cli-schema.svg?style=flat)](https://www.npmjs.com/package/base-cli-schema) [![NPM downloads](https://img.shields.io/npm/dm/base-cli-schema.svg?style=flat)](https://npmjs.org/package/base-cli-schema) [![Build Status](https://img.shields.io/travis/jonschlinkert/base-cli-schema.svg?style=flat)](https://travis-ci.org/jonschlinkert/base-cli-schema)
|
2 |
|
3 | > Schema for the base-cli plugin, used for normalizing argv values before passing them to cli.process().
|
4 |
|
5 | ## Install
|
6 |
|
7 | Install with [npm](https://www.npmjs.com/):
|
8 |
|
9 | ```sh
|
10 | $ npm install base-cli-schema --save
|
11 | ```
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```js
|
16 | var argv = require('minimist')(process.argv.slice(2));
|
17 | var Base = require('base');
|
18 | var cliSchema = require('base-cli-schema');
|
19 |
|
20 | var app = new Base();
|
21 | app.use(cli());
|
22 | var schema = cliSchema(app);
|
23 |
|
24 | var obj = schema.normalize(argv);
|
25 | console.log(obj);
|
26 | ```
|
27 |
|
28 | ### Custom fields
|
29 |
|
30 | Field names correspond to properties on the parsed `argv` object.
|
31 |
|
32 | ```js
|
33 | var schema = cliSchema(app)
|
34 | .field('foo', 'string', {
|
35 | normalize: function(val, key, config, schema) {
|
36 | // do stuff to val
|
37 | return 'bar';
|
38 | }
|
39 | })
|
40 |
|
41 | var obj = schema.normalize(argv);
|
42 | console.log(obj);
|
43 | //=> {foo: 'bar'}
|
44 | ```
|
45 |
|
46 | ## Related projects
|
47 |
|
48 | You might also be interested in these projects:
|
49 |
|
50 | * [base-cli-process](https://www.npmjs.com/package/base-cli-process): Normalizers for common argv commands handled by the base-cli plugin. Also pre-processes the given object… [more](https://www.npmjs.com/package/base-cli-process) | [homepage](https://github.com/jonschlinkert/base-cli-process)
|
51 | * [base-cli](https://www.npmjs.com/package/base-cli): Plugin for base-methods that maps built-in methods to CLI args (also supports methods from a… [more](https://www.npmjs.com/package/base-cli) | [homepage](https://github.com/node-base/base-cli)
|
52 | * [base-option](https://www.npmjs.com/package/base-option): Adds a few options methods to base, like `option`, `enable` and `disable`. See the readme… [more](https://www.npmjs.com/package/base-option) | [homepage](https://github.com/node-base/base-option)
|
53 | * [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://www.npmjs.com/package/base) | [homepage](https://github.com/node-base/base)
|
54 |
|
55 | ## Contributing
|
56 |
|
57 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/base-cli-schema/issues/new).
|
58 |
|
59 | ## Building docs
|
60 |
|
61 | Generate readme and API documentation with [verb](https://github.com/verbose/verb):
|
62 |
|
63 | ```sh
|
64 | $ npm install verb && npm run docs
|
65 | ```
|
66 |
|
67 | Or, if [verb](https://github.com/verbose/verb) is installed globally:
|
68 |
|
69 | ```sh
|
70 | $ verb
|
71 | ```
|
72 |
|
73 | ## Running tests
|
74 |
|
75 | Install dev dependencies:
|
76 |
|
77 | ```sh
|
78 | $ npm install -d && npm test
|
79 | ```
|
80 |
|
81 | ## Author
|
82 |
|
83 | **Jon Schlinkert**
|
84 |
|
85 | * [github/jonschlinkert](https://github.com/jonschlinkert)
|
86 | * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
|
87 |
|
88 | ## License
|
89 |
|
90 | Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
|
91 | Released under the [MIT license](https://github.com/jonschlinkert/base-cli-schema/blob/master/LICENSE).
|
92 |
|
93 | ***
|
94 |
|
95 | _This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on April 22, 2016._ |
\ | No newline at end of file |