@untool/yargs
Advanced tools
Comparing version 0.4.1 to 0.4.3
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="0.4.3"></a> | ||
## [0.4.3](https://github.com/untool/untool/compare/v0.4.2...v0.4.3) (2018-04-24) | ||
### Bug Fixes | ||
* **yargs:** make sure all commands are registered ([623cfe9](https://github.com/untool/untool/commit/623cfe9)), closes [#15](https://github.com/untool/untool/issues/15) | ||
<a name="0.4.1"></a> | ||
@@ -8,0 +19,0 @@ ## [0.4.1](https://github.com/untool/untool/compare/v0.4.0...v0.4.1) (2018-04-20) |
13
index.js
@@ -5,12 +5,11 @@ #!/usr/bin/env node | ||
const createYargs = require('yargs'); | ||
const chalk = require('chalk'); | ||
const { bootstrap } = require('@untool/core'); | ||
exports.run = (...argv) => { | ||
const yargs = argv.length ? createYargs(argv) : createYargs; | ||
exports.run = (...args) => { | ||
const yargs = args.length ? createYargs(args) : createYargs; | ||
if (yargs.argv.production || yargs.argv.p) { | ||
process.env.NODE_ENV = 'production'; | ||
} | ||
const { registerCommands, logError } = bootstrap(); | ||
const { registerCommands, handleArguments, logError } = bootstrap(); | ||
@@ -29,5 +28,5 @@ const onError = error => void logError(error) || process.exit(1); | ||
.strict() | ||
.demandCommand(1, ''), | ||
chalk | ||
); | ||
.demandCommand(1, '') | ||
.check(handleArguments) | ||
).parse(); | ||
}; | ||
@@ -34,0 +33,0 @@ |
/* eslint-disable no-console */ | ||
const chalk = require('chalk'); | ||
const { sync: { pipe, override } } = require('mixinable'); | ||
@@ -7,8 +9,15 @@ | ||
class YargsMixin extends Mixin { | ||
registerCommands(yargs, chalk) { | ||
registerCommands(yargs) { | ||
yargs.option('log', { | ||
alias: 'l', | ||
default: 'info', | ||
describe: 'Define log level ()', | ||
type: 'string', | ||
}); | ||
return yargs; | ||
} | ||
handleArguments(argv) { | ||
const levels = ['debug', 'info', 'warn', 'error', 'silent']; | ||
const index = levels.indexOf(yargs.alias('l', 'log').argv.log); | ||
const index = levels.indexOf(argv.log || argv.l); | ||
this.levels = levels.slice(Math.max(index, 0), -1); | ||
this.chalk = chalk; | ||
return yargs; | ||
} | ||
@@ -18,3 +27,3 @@ logDebug(...args) { | ||
if (this.levels && this.levels.includes('debug')) { | ||
console.log(this.chalk.bold(`${namespace} debug`)); | ||
console.log(chalk.bold(`${namespace} debug`)); | ||
console.debug(...args); | ||
@@ -26,3 +35,3 @@ } | ||
if (this.levels && this.levels.includes('info')) { | ||
console.log(this.chalk.bold(`${namespace} info`)); | ||
console.log(chalk.bold(`${namespace} info`)); | ||
console.info(...args); | ||
@@ -34,3 +43,3 @@ } | ||
if (this.levels && this.levels.includes('warn')) { | ||
console.log(this.chalk.yellow.bold(`${namespace} warn`)); | ||
console.log(chalk.yellow.bold(`${namespace} warn`)); | ||
console.warn(...args); | ||
@@ -42,3 +51,3 @@ } | ||
if (!this.levels || this.levels.includes('error')) { | ||
console.log(this.chalk.red.bold(`${namespace} error`)); | ||
console.log(chalk.red.bold(`${namespace} error`)); | ||
console.error(error.stack ? error.stack.toString() : error.toString()); | ||
@@ -50,3 +59,3 @@ } | ||
if (this.levels && this.levels.includes('info')) { | ||
console.log(this.chalk.bold(`${namespace} stats`)); | ||
console.log(chalk.bold(`${namespace} stats`)); | ||
console.info( | ||
@@ -61,2 +70,6 @@ stats.toString({ chunks: false, modules: false, entrypoints: false }) | ||
registerCommands: pipe, | ||
handleArguments: function(functions, ...args) { | ||
functions.forEach(fn => fn(...args)); | ||
return true; | ||
}, | ||
logDebug: override, | ||
@@ -63,0 +76,0 @@ logInfo: override, |
{ | ||
"name": "@untool/yargs", | ||
"version": "0.4.1", | ||
"version": "0.4.3", | ||
"description": "untool yargs mixin", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@untool/core": "^0.4.1", | ||
"@untool/core": "^0.4.3", | ||
"chalk": "^2.3.1", | ||
@@ -31,0 +31,0 @@ "mixinable": "^2.0.0", |
@@ -44,3 +44,3 @@ # `@untool/yargs` | ||
This is the most relevant hook provided by `@untool/yargs`: it enables other mixins to register their respective commands. Implementations of this mixin method will receive two arguments: a [`yargs`](http://yargs.js.org) instance and [`chalk`](https://github.com/chalk/chalk) to help you format your console output. Implementations need to return the `yargs` instance that they were called with. | ||
This is the most relevant hook provided by `@untool/yargs`: it enables other mixins to register their respective commands. Implementations of this mixin method will receive two arguments: a [`yargs`](http://yargs.js.org) instance and the command line arguments `@untool/yargs` received. Implementations need to return the `yargs` instance that they were called with. | ||
@@ -69,4 +69,3 @@ ```javascript | ||
foo() { | ||
const { logInfo } = this.core; | ||
logInfo('foo!'); | ||
this.logInfo('foo!'); | ||
} | ||
@@ -73,0 +72,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8917
98
78
Updated@untool/core@^0.4.3