@untool/yargs
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.2.0](https://github.com/untool/untool/compare/v1.1.0...v1.2.0) (2019-02-27) | ||
### Features | ||
* **yargs:** add arg validation to mixin methods ([cced80e](https://github.com/untool/untool/commit/cced80e)) | ||
# [1.1.0](https://github.com/untool/untool/compare/v1.0.0...v1.1.0) (2019-02-14) | ||
@@ -8,0 +19,0 @@ |
12
index.js
@@ -6,3 +6,6 @@ #!/usr/bin/env node | ||
const { initialize } = require('@untool/core'); | ||
const { | ||
initialize, | ||
internal: { invariant }, | ||
} = require('@untool/core'); | ||
@@ -19,5 +22,6 @@ const configure = (config, options) => ({ | ||
const { registerCommands, handleArguments, handleError } = core; | ||
if (!(registerCommands && handleArguments && handleError)) { | ||
throw new Error("Can't use @untool/yargs mixin"); | ||
} | ||
invariant( | ||
registerCommands && handleArguments && handleError, | ||
"Can't use @untool/yargs mixin" | ||
); | ||
process.on('uncaughtException', handleError); | ||
@@ -24,0 +28,0 @@ process.on('unhandledRejection', handleError); |
'use strict'; | ||
const isPlainObject = require('is-plain-object'); | ||
const { | ||
@@ -7,4 +9,12 @@ sync: { sequence, override }, | ||
const { Mixin } = require('@untool/core'); | ||
const { | ||
Mixin, | ||
internal: { validate, invariant }, | ||
} = require('@untool/core'); | ||
const sequenceWithReturn = (functions, definition, ...args) => { | ||
sequence(functions, definition, ...args); | ||
return definition; | ||
}; | ||
class YargsMixin extends Mixin { | ||
@@ -19,8 +29,23 @@ handleError(error) { | ||
YargsMixin.strategies = { | ||
registerCommands: sequence, | ||
configureCommand: (...args) => sequence(...args) && args[1], | ||
handleArguments: sequence, | ||
handleError: override, | ||
registerCommands: validate(sequence, ([yargs]) => { | ||
invariant( | ||
yargs && typeof yargs.command === 'function', | ||
'registerCommands(): Received invalid yargs instance' | ||
); | ||
}), | ||
configureCommand: validate(sequenceWithReturn, ([definition]) => { | ||
invariant( | ||
isPlainObject(definition) && definition.command && definition.builder, | ||
'configureCommand(): Received invalid command definition' | ||
); | ||
}), | ||
handleArguments: validate(sequence, ([args]) => { | ||
invariant( | ||
isPlainObject(args), | ||
'handleArguments(): Received invalid arguments object' | ||
); | ||
}), | ||
handleError: validate(override, () => {}, () => process.exit(1)), | ||
}; | ||
module.exports = YargsMixin; |
{ | ||
"name": "@untool/yargs", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "untool yargs mixin", | ||
@@ -22,3 +22,3 @@ "bin": { | ||
"dependencies": { | ||
"@untool/core": "^1.1.0", | ||
"@untool/core": "^1.2.0", | ||
"mixinable": "^4.0.0", | ||
@@ -31,3 +31,3 @@ "pretty-ms": "^4.0.0", | ||
}, | ||
"gitHead": "e92a4e17440f172b7211c57d7bbf9badd34ec8b3" | ||
"gitHead": "0576dcfa7e743599b9f020024e1f479cdd7044b9" | ||
} |
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
21474
168
Updated@untool/core@^1.2.0