UNPKG

3.29 kBMarkdownView Raw
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
3Schema for the base-cli plugin, used for normalizing argv values before passing them to cli.process().
4
5## Install
6
7Install with [npm](https://www.npmjs.com/):
8
9```sh
10$ npm install base-cli-schema --save
11```
12
13## Usage
14
15```js
16var argv = require('minimist')(process.argv.slice(2));
17var Base = require('base');
18var cliSchema = require('base-cli-schema');
19
20var app = new Base();
21app.use(cli());
22var schema = cliSchema(app);
23
24var obj = schema.normalize(argv);
25console.log(obj);
26```
27
28### Custom fields
29
30Field names correspond to properties on the parsed `argv` object.
31
32```js
33var 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
41var obj = schema.normalize(argv);
42console.log(obj);
43//=> {foo: 'bar'}
44```
45
46## Related projects
47
48You 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
57Pull 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
61Generate readme and API documentation with [verb](https://github.com/verbose/verb):
62
63```sh
64$ npm install verb && npm run docs
65```
66
67Or, if [verb](https://github.com/verbose/verb) is installed globally:
68
69```sh
70$ verb
71```
72
73## Running tests
74
75Install 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
90Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
91Released 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 May 07, 2016._
\No newline at end of file