common-bin-plus
advanced common-bin for cli usage
Installation
npm i common-bin-plus --save
Write your own cli
see common-bin for more details.
Feature
Logger
https://github.com/node-modules/zlogger
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=CLI
- programmatically:
logger.level = 'DEBUG'
Prompt
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 :
const coffee = require('coffee');
describe('test/index.test.js', () => {
it('should work', () => {
return coffee.fork('/path/to/cli')
.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();
});
}):