https://github.com/node-modules/common-bin-plus
advanced common-bin for cli usage
https://github.com/node-modules/common-bin-plus
common-bin
Last synced: 7 months ago
JSON representation
advanced common-bin for cli usage
- Host: GitHub
- URL: https://github.com/node-modules/common-bin-plus
- Owner: node-modules
- Created: 2018-12-13T09:14:56.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-11-10T11:06:13.000Z (about 3 years ago)
- Last Synced: 2025-05-06T03:04:02.243Z (8 months ago)
- Topics: common-bin
- Language: JavaScript
- Size: 25.4 KB
- Stars: 4
- Watchers: 13
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
Awesome Lists containing this project
README
# common-bin-plus
advanced [common-bin](https://github.com/node-modules/common-bin) for cli usage
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![NPM download][download-image]][download-url]
[npm-image]: https://img.shields.io/npm/v/common-bin-plus.svg?style=flat-square
[npm-url]: https://npmjs.org/package/common-bin-plus
[travis-image]: https://img.shields.io/travis/node-modules/common-bin-plus.svg?style=flat-square
[travis-url]: https://travis-ci.org/node-modules/common-bin-plus
[codecov-image]: https://codecov.io/gh/node-modules/common-bin-plus/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/node-modules/common-bin-plus
[david-image]: https://img.shields.io/david/node-modules/common-bin-plus.svg?style=flat-square
[david-url]: https://david-dm.org/node-modules/common-bin-plus
[snyk-image]: https://snyk.io/test/npm/common-bin-plus/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/common-bin-plus
[download-image]: https://img.shields.io/npm/dm/common-bin-plus.svg?style=flat-square
[download-url]: https://npmjs.org/package/common-bin-plus
## Installation
```bash
npm i common-bin-plus --save
```
## Write your own cli
see [common-bin](https://github.com/node-modules/common-bin) for more details.
## Feature
### Logger
https://github.com/unjs/consola
```js
this.logger.info('hello info level');
this.logger.warn('hello warn level');
this.logger.error(new Error('hello error level'));
this.logger.debug('hello debug level');
```
`debug` log is disabled by default, you could enable it by:
- command line argv: `--verbose`
- process env: `DEBUG=*` or `DEBUG=${cliName}`
- programmatically: `logger.level = 'DEBUG'`
## Prompt
```js
const answers = await this.prompt([
{
type: 'input',
name: 'name',
message: 'What is your name:',
}, {
type: 'list',
name: 'type',
message: 'Choose a boilerplate:',
choices: [ 'empty', 'simple', 'plugin', 'framework' ],
},
], {});
this.logger.info(answers);
```
## Unit Testing
Use [coffee](https://github.com/node-modules/coffee) :
```js
const coffee = require('coffee');
describe('test/index.test.js', () => {
it('should work', () => {
return coffee.fork('/path/to/cli')
// .debug()
.waitForPrompt()
.write('tz\n')
.writeKey('DOWN', 'ENTER')
.write('this is a desc\n')
.expect('stdout', /{ name: 'tz', type: 'simple' }/)
.expect('stdout', /{ description: 'this is a desc' }/)
.expect('code', 0)
.end();
});
}):
```