From dae9c5c88efdc2efb3383e0c024bd340954b1f67 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Tue, 14 Mar 2017 12:58:33 -0700 Subject: [PATCH 1/7] [wip] added duration example --- src/commands/duration.js | 18 ++++++++++++++++++ src/index.js | 6 ++++-- src/mixins/duration.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/commands/duration.js create mode 100644 src/mixins/duration.js diff --git a/src/commands/duration.js b/src/commands/duration.js new file mode 100644 index 0000000..de9921b --- /dev/null +++ b/src/commands/duration.js @@ -0,0 +1,18 @@ +// @ flow + +import Command from 'cli-engine-command' +import DurationMixin from '../mixins/duration' + +export default class extends DurationMixin(Command) { + static topic = 'cli' + static command = 'duration' + static description = 'this is an example command showing duration parsing' + + static flags = [ + {name: 'foo'} + ] + + run () { + this.log(`duration: ${this.duration}`) + } +} diff --git a/src/index.js b/src/index.js index 143f283..f826392 100644 --- a/src/index.js +++ b/src/index.js @@ -4,5 +4,7 @@ export const topics = [ {name: 'cli', description: 'example CLI engine topic'} ] -import CLI from './commands/cli' -export const commands = [CLI] +export const commands = [ + require('./commands/cli'), + require('./commands/duration') +] diff --git a/src/mixins/duration.js b/src/mixins/duration.js new file mode 100644 index 0000000..02d0310 --- /dev/null +++ b/src/mixins/duration.js @@ -0,0 +1,29 @@ +// @flow + +import Command, {type Flag} from 'cli-engine-command' // eslint-disable-line + +const FLAG: Flag = { + name: 'duration', + description: 'a duration', + required: true, + hasValue: true +} + +declare class App extends Command { + duration: Date +} + +export default function > (Base: T): $Shape> { + return class DurationMixin extends Base { + static get flags (): Flag[] { return this._flags.concat([FLAG]) } + static set flags (flags: Flag[]) { this._flags = flags } + + get duration (): Date { + this.inspect(this.constructor.flags) + + // this is a little gross but I think needed to cast it to a string + let duration = (((this.flags.duration): any): string) + return new Date(duration) + } + } +} From 5fa5361f031f1b3c3f0e7d335d91d73405ed3bbe Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Tue, 14 Mar 2017 13:20:36 -0700 Subject: [PATCH 2/7] remove debug statements --- src/commands/duration.js | 4 ---- src/mixins/duration.js | 4 +--- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/commands/duration.js b/src/commands/duration.js index de9921b..bbd4d5a 100644 --- a/src/commands/duration.js +++ b/src/commands/duration.js @@ -8,10 +8,6 @@ export default class extends DurationMixin(Command) { static command = 'duration' static description = 'this is an example command showing duration parsing' - static flags = [ - {name: 'foo'} - ] - run () { this.log(`duration: ${this.duration}`) } diff --git a/src/mixins/duration.js b/src/mixins/duration.js index 02d0310..8262439 100644 --- a/src/mixins/duration.js +++ b/src/mixins/duration.js @@ -15,12 +15,10 @@ declare class App extends Command { export default function > (Base: T): $Shape> { return class DurationMixin extends Base { - static get flags (): Flag[] { return this._flags.concat([FLAG]) } + static get flags (): Flag[] { return super.flags.concat([FLAG]) } static set flags (flags: Flag[]) { this._flags = flags } get duration (): Date { - this.inspect(this.constructor.flags) - // this is a little gross but I think needed to cast it to a string let duration = (((this.flags.duration): any): string) return new Date(duration) From a2b0252e24cd28065fdb5c10d5b194ac46318a0d Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Tue, 14 Mar 2017 13:28:53 -0700 Subject: [PATCH 3/7] flow fix --- src/commands/duration.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/duration.js b/src/commands/duration.js index bbd4d5a..8e504d2 100644 --- a/src/commands/duration.js +++ b/src/commands/duration.js @@ -1,4 +1,4 @@ -// @ flow +// @flow import Command from 'cli-engine-command' import DurationMixin from '../mixins/duration' @@ -9,6 +9,6 @@ export default class extends DurationMixin(Command) { static description = 'this is an example command showing duration parsing' run () { - this.log(`duration: ${this.duration}`) + this.log(`duration: ${this.duration.toString()}`) } } From 24030bda1406d8959f20929044d455a75e23a4fe Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Wed, 15 Mar 2017 09:15:31 -0700 Subject: [PATCH 4/7] use new mixin syntax --- src/commands/duration.js | 6 +- src/mixins/duration.js | 26 ++-- yarn.lock | 279 +++++++++++++++++++++------------------ 3 files changed, 164 insertions(+), 147 deletions(-) diff --git a/src/commands/duration.js b/src/commands/duration.js index 8e504d2..7ca8b96 100644 --- a/src/commands/duration.js +++ b/src/commands/duration.js @@ -1,13 +1,15 @@ // @flow import Command from 'cli-engine-command' -import DurationMixin from '../mixins/duration' +import Duration from '../mixins/duration' -export default class extends DurationMixin(Command) { +export default class extends Command { static topic = 'cli' static command = 'duration' static description = 'this is an example command showing duration parsing' + duration = new Duration(this) + run () { this.log(`duration: ${this.duration.toString()}`) } diff --git a/src/mixins/duration.js b/src/mixins/duration.js index 8262439..9b90b34 100644 --- a/src/mixins/duration.js +++ b/src/mixins/duration.js @@ -1,27 +1,23 @@ // @flow -import Command, {type Flag} from 'cli-engine-command' // eslint-disable-line +import type Command from 'cli-engine-command' -const FLAG: Flag = { +export const FLAG = { name: 'duration', description: 'a duration', required: true, hasValue: true } -declare class App extends Command { - duration: Date -} - -export default function > (Base: T): $Shape> { - return class DurationMixin extends Base { - static get flags (): Flag[] { return super.flags.concat([FLAG]) } - static set flags (flags: Flag[]) { this._flags = flags } +export default class DurationMixin { + cmd: Command + constructor (cmd: Command) { + this.cmd = cmd + } - get duration (): Date { - // this is a little gross but I think needed to cast it to a string - let duration = (((this.flags.duration): any): string) - return new Date(duration) - } + get duration (): Date { + // this is a little gross but I think needed to cast it to a string + let duration = this.cmd.flags.duration + return new Date(duration) } } diff --git a/yarn.lock b/yarn.lock index d483eda..fdb7cd8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -30,6 +30,13 @@ acorn@^3.0.4: version "3.3.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a" +ajv@^4.9.1: + version "4.11.5" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.5.tgz#b6ee74657b993a01dce44b7944d56f485828d5bd" + dependencies: + co "^4.6.0" + json-stable-stringify "^1.0.1" + align-text@^0.1.1, align-text@^0.1.3: version "0.1.4" resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117" @@ -137,14 +144,14 @@ asn1@~0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86" +assert-plus@1.0.0, assert-plus@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" + assert-plus@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-0.2.0.tgz#d74e1b87e7affc0db8aadb7021f3fe48101ab234" -assert-plus@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" - async-each@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d" @@ -159,10 +166,6 @@ async@^2.1.4: dependencies: lodash "^4.14.0" -async@~0.2.6: - version "0.2.10" - resolved "https://registry.yarnpkg.com/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1" - asynckit@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" @@ -432,8 +435,8 @@ block-stream@*: inherits "~2.0.0" bluebird@^3.1.1: - version "3.4.7" - resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.4.7.tgz#f72d760be09b7f76d08ed8fae98b289a8d05fab3" + version "3.5.0" + resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.0.tgz#791420d7f551eea2897453a8a77653f96606d67c" boom@2.x.x: version "2.10.1" @@ -519,9 +522,9 @@ cardinal@^1.0.0: ansicolors "~0.2.1" redeyed "~1.0.0" -caseless@~0.11.0: - version "0.11.0" - resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.11.0.tgz#715b96ea9841593cc33067923f5ec60ebda4f7d7" +caseless@~0.12.0: + version "0.12.0" + resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" center-align@^0.1.1: version "0.1.3" @@ -610,6 +613,10 @@ cliui@^3.0.3, cliui@^3.2.0: strip-ansi "^3.0.1" wrap-ansi "^2.0.0" +co@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" + code-point-at@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" @@ -621,8 +628,8 @@ color-convert@^1.0.0: color-name "^1.1.1" color-name@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.1.tgz#4b1415304cf50028ea81643643bd82ea05803689" + version "1.1.2" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.2.tgz#5c8ab72b64bd2215d617ae9559ebb148475cf98d" colors@^1.1.2: version "1.1.2" @@ -634,7 +641,7 @@ combined-stream@^1.0.5, combined-stream@~1.0.5: dependencies: delayed-stream "~1.0.0" -commander@^2.8.1, commander@^2.9.0: +commander@^2.8.1: version "2.9.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4" dependencies: @@ -698,11 +705,11 @@ cssom@0.3.x, "cssom@>= 0.3.2 < 0.4.0": dependencies: cssom "0.3.x" -d@^0.1.1, d@~0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/d/-/d-0.1.1.tgz#da184c535d18d8ee7ba2aa229b914009fae11309" +d@1: + version "1.0.0" + resolved "https://registry.yarnpkg.com/d/-/d-1.0.0.tgz#754bb5bfe55451da69a58b94d45f4c5b0462d58f" dependencies: - es5-ext "~0.10.2" + es5-ext "^0.10.9" dashdash@^1.12.0: version "1.14.1" @@ -715,8 +722,8 @@ debug-log@^1.0.0: resolved "https://registry.yarnpkg.com/debug-log/-/debug-log-1.0.1.tgz#2307632d4c04382b8df8a32f70b895046d52745f" debug@^2.1.1, debug@^2.2.0: - version "2.6.1" - resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.1.tgz#79855090ba2c4e3115cc7d8769491d58f0491351" + version "2.6.3" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.3.tgz#0f7eb8c30965ec08c72accfa0130c8b79984141d" dependencies: ms "0.7.2" @@ -823,8 +830,8 @@ ecc-jsbn@~0.1.1: prr "~0.0.0" error-ex@^1.2.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.0.tgz#e67b43f3e82c96ea3a584ffee0b9fc3325d802d9" + version "1.3.1" + resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.1.tgz#f855a86ce61adc4e8621c3cda21e7a7612c3a8dc" dependencies: is-arrayish "^0.2.1" @@ -845,57 +852,57 @@ es-to-primitive@^1.1.1: is-date-object "^1.0.1" is-symbol "^1.0.1" -es5-ext@^0.10.7, es5-ext@^0.10.8, es5-ext@~0.10.11, es5-ext@~0.10.2, es5-ext@~0.10.7: - version "0.10.12" - resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.12.tgz#aa84641d4db76b62abba5e45fd805ecbab140047" +es5-ext@^0.10.14, es5-ext@^0.10.9, es5-ext@~0.10.14: + version "0.10.14" + resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.14.tgz#625bc9ab9cac0f6fb9dc271525823d1800b3d360" dependencies: es6-iterator "2" es6-symbol "~3.1" -es6-iterator@2: - version "2.0.0" - resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.0.tgz#bd968567d61635e33c0b80727613c9cb4b096bac" +es6-iterator@2, es6-iterator@^2.0.1, es6-iterator@~2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.1.tgz#8e319c9f0453bf575d374940a655920e59ca5512" dependencies: - d "^0.1.1" - es5-ext "^0.10.7" - es6-symbol "3" + d "1" + es5-ext "^0.10.14" + es6-symbol "^3.1" es6-map@^0.1.3: - version "0.1.4" - resolved "https://registry.yarnpkg.com/es6-map/-/es6-map-0.1.4.tgz#a34b147be224773a4d7da8072794cefa3632b897" + version "0.1.5" + resolved "https://registry.yarnpkg.com/es6-map/-/es6-map-0.1.5.tgz#9136e0503dcc06a301690f0bb14ff4e364e949f0" dependencies: - d "~0.1.1" - es5-ext "~0.10.11" - es6-iterator "2" - es6-set "~0.1.3" - es6-symbol "~3.1.0" - event-emitter "~0.3.4" + d "1" + es5-ext "~0.10.14" + es6-iterator "~2.0.1" + es6-set "~0.1.5" + es6-symbol "~3.1.1" + event-emitter "~0.3.5" -es6-set@~0.1.3: - version "0.1.4" - resolved "https://registry.yarnpkg.com/es6-set/-/es6-set-0.1.4.tgz#9516b6761c2964b92ff479456233a247dc707ce8" +es6-set@~0.1.5: + version "0.1.5" + resolved "https://registry.yarnpkg.com/es6-set/-/es6-set-0.1.5.tgz#d2b3ec5d4d800ced818db538d28974db0a73ccb1" dependencies: - d "~0.1.1" - es5-ext "~0.10.11" - es6-iterator "2" - es6-symbol "3" - event-emitter "~0.3.4" + d "1" + es5-ext "~0.10.14" + es6-iterator "~2.0.1" + es6-symbol "3.1.1" + event-emitter "~0.3.5" -es6-symbol@3, es6-symbol@~3.1, es6-symbol@~3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.0.tgz#94481c655e7a7cad82eba832d97d5433496d7ffa" +es6-symbol@3.1.1, es6-symbol@^3.1, es6-symbol@^3.1.1, es6-symbol@~3.1, es6-symbol@~3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.1.tgz#bf00ef4fdab6ba1b46ecb7b629b4c7ed5715cc77" dependencies: - d "~0.1.1" - es5-ext "~0.10.11" + d "1" + es5-ext "~0.10.14" es6-weak-map@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/es6-weak-map/-/es6-weak-map-2.0.1.tgz#0d2bbd8827eb5fb4ba8f97fbfea50d43db21ea81" + version "2.0.2" + resolved "https://registry.yarnpkg.com/es6-weak-map/-/es6-weak-map-2.0.2.tgz#5e3ab32251ffd1538a1f8e5ffa1357772f92d96f" dependencies: - d "^0.1.1" - es5-ext "^0.10.8" - es6-iterator "2" - es6-symbol "3" + d "1" + es5-ext "^0.10.14" + es6-iterator "^2.0.1" + es6-symbol "^3.1.1" escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: version "1.0.5" @@ -1033,12 +1040,12 @@ esutils@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" -event-emitter@~0.3.4: - version "0.3.4" - resolved "https://registry.yarnpkg.com/event-emitter/-/event-emitter-0.3.4.tgz#8d63ddfb4cfe1fae3b32ca265c4c720222080bb5" +event-emitter@~0.3.5: + version "0.3.5" + resolved "https://registry.yarnpkg.com/event-emitter/-/event-emitter-0.3.5.tgz#df8c69eef1647923c7157b9ce83840610b02cc39" dependencies: - d "~0.1.1" - es5-ext "~0.10.7" + d "1" + es5-ext "~0.10.14" exec-sh@^0.2.0: version "0.2.0" @@ -1185,15 +1192,15 @@ flow-typed@2.0.0: which "^1.2.11" yargs "^4.2.0" -for-in@^0.1.5: - version "0.1.6" - resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.6.tgz#c9f96e89bfad18a545af5ec3ed352a1d9e5b4dc8" +for-in@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" for-own@^0.1.4: - version "0.1.4" - resolved "https://registry.yarnpkg.com/for-own/-/for-own-0.1.4.tgz#0149b41a39088c7515f51ebe1c1386d45f935072" + version "0.1.5" + resolved "https://registry.yarnpkg.com/for-own/-/for-own-0.1.5.tgz#5265c681a4f294dabbf17c9509b6763aa84510ce" dependencies: - for-in "^0.1.5" + for-in "^1.0.1" foreach@^2.0.5: version "2.0.5" @@ -1252,8 +1259,8 @@ fstream-ignore@~1.0.5: minimatch "^3.0.0" fstream@^1.0.0, fstream@^1.0.2, fstream@~1.0.10: - version "1.0.10" - resolved "https://registry.yarnpkg.com/fstream/-/fstream-1.0.10.tgz#604e8a92fe26ffd9f6fae30399d4984e1ab22822" + version "1.0.11" + resolved "https://registry.yarnpkg.com/fstream/-/fstream-1.0.11.tgz#5c1fb1f117477114f0632a0eb4b71b3cb0fd3171" dependencies: graceful-fs "^4.1.2" inherits "~2.0.0" @@ -1388,14 +1395,16 @@ handlebars@^4.0.3: optionalDependencies: uglify-js "^2.6" -har-validator@~2.0.6: - version "2.0.6" - resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-2.0.6.tgz#cdcbc08188265ad119b6a5a7c8ab70eecfb5d27d" +har-schema@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-1.0.5.tgz#d263135f43307c02c602afc8fe95970c0151369e" + +har-validator@~4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-4.2.1.tgz#33481d0f1bbff600dd203d75812a6a5fba002e2a" dependencies: - chalk "^1.1.1" - commander "^2.9.0" - is-my-json-valid "^2.12.4" - pinkie-promise "^2.0.0" + ajv "^4.9.1" + har-schema "^1.0.5" has-ansi@^2.0.0: version "2.0.0" @@ -1438,8 +1447,8 @@ home-or-tmp@^2.0.0: os-tmpdir "^1.0.1" hosted-git-info@^2.1.4: - version "2.2.0" - resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.2.0.tgz#7a0d097863d886c0fabbdcd37bf1758d8becf8a5" + version "2.3.1" + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.3.1.tgz#ac439421605f0beb0ea1349de7d8bb28e50be1dd" html-encoding-sniffer@^1.0.1: version "1.0.1" @@ -1464,8 +1473,8 @@ iconv-lite@0.4.13: resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.13.tgz#1f88aba4ab0b1508e8312acc39345f36e992e2f2" ignore@^3.0.9, ignore@^3.2.0: - version "3.2.4" - resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.2.4.tgz#4055e03596729a8fabe45a43c100ad5ed815c4e8" + version "3.2.6" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.2.6.tgz#26e8da0644be0bb4cb39516f6c79f0e0f4ffe48c" imurmurhash@^0.1.4: version "0.1.4" @@ -1529,8 +1538,8 @@ is-binary-path@^1.0.0: binary-extensions "^1.0.0" is-buffer@^1.0.2, is-buffer@~1.1.1: - version "1.1.4" - resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.4.tgz#cfc86ccd5dc5a52fa80489111c6920c457e2d98b" + version "1.1.5" + resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc" is-builtin-module@^1.0.0: version "1.0.0" @@ -1588,9 +1597,9 @@ is-glob@^2.0.0, is-glob@^2.0.1: dependencies: is-extglob "^1.0.0" -is-my-json-valid@^2.10.0, is-my-json-valid@^2.12.4: - version "2.15.0" - resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.15.0.tgz#936edda3ca3c211fd98f3b2d3e08da43f7b2915b" +is-my-json-valid@^2.10.0: + version "2.16.0" + resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.16.0.tgz#f079dd9bfdae65ee2038aae8acbc86ab109e3693" dependencies: generate-function "^2.0.0" generate-object-property "^1.1.0" @@ -1621,7 +1630,7 @@ is-path-inside@^1.0.0: is-posix-bracket@^0.1.0: version "0.1.1" - resolved "http://registry.npmjs.org/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz#3334dc79774368e92f016e6fbc0a88f5cd6e6bc4" + resolved "https://registry.yarnpkg.com/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz#3334dc79774368e92f016e6fbc0a88f5cd6e6bc4" is-primitive@^2.0.0: version "2.0.0" @@ -1962,8 +1971,8 @@ js-tokens@^3.0.0: resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7" js-yaml@^3.5.1, js-yaml@^3.7.0: - version "3.8.1" - resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.1.tgz#782ba50200be7b9e5a8537001b7804db3ad02628" + version "3.8.2" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.2.tgz#02d3e2c0f6beab20248d412c352203827d786721" dependencies: argparse "^1.0.7" esprima "^3.1.1" @@ -1973,8 +1982,8 @@ jsbn@~0.1.0: resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" jsdom@^9.11.0: - version "9.11.0" - resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-9.11.0.tgz#a95b0304e521a2ca5a63c6ea47bf7708a7a84591" + version "9.12.0" + resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-9.12.0.tgz#e8c546fffcb06c00d4833ca84410fed7f8a097d4" dependencies: abab "^1.0.3" acorn "^4.0.4" @@ -2033,9 +2042,10 @@ jsonpointer@^4.0.0: resolved "https://registry.yarnpkg.com/jsonpointer/-/jsonpointer-4.0.1.tgz#4fd92cb34e0e9db3c89c8622ecf51f9b978c6cb9" jsprim@^1.2.2: - version "1.3.1" - resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.3.1.tgz#2a7256f70412a29ee3670aaca625994c4dcff252" + version "1.4.0" + resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.0.tgz#a3b87e40298d8c380552d8cc7628a0bb95a22918" dependencies: + assert-plus "1.0.0" extsprintf "1.0.2" json-schema "0.2.3" verror "1.3.6" @@ -2246,8 +2256,8 @@ node-int64@^0.4.0: resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" node-notifier@^5.0.1: - version "5.0.2" - resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-5.0.2.tgz#4438449fe69e321f941cef943986b0797032701b" + version "5.1.2" + resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-5.1.2.tgz#2fa9e12605fa10009d44549d6fcd8a63dde0e4ff" dependencies: growly "^1.3.0" semver "^5.3.0" @@ -2275,8 +2285,8 @@ nopt@~3.0.6: abbrev "1" normalize-package-data@^2.3.2: - version "2.3.5" - resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.3.5.tgz#8d924f142960e1777e7ffe170543631cc7cb02df" + version "2.3.6" + resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.3.6.tgz#498fa420c96401f787402ba21e600def9f981fff" dependencies: hosted-git-info "^2.1.4" is-builtin-module "^1.0.0" @@ -2438,6 +2448,10 @@ path-type@^1.0.0: pify "^2.0.0" pinkie-promise "^2.0.0" +performance-now@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-0.2.0.tgz#33ef30c5c77d4ea21c5a53869d91b56d8f2555e5" + pify@^2.0.0: version "2.3.0" resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" @@ -2509,9 +2523,9 @@ punycode@^1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" -qs@~6.3.0: - version "6.3.1" - resolved "https://registry.yarnpkg.com/qs/-/qs-6.3.1.tgz#918c0b3bcd36679772baf135b1acb4c1651ed79d" +qs@~6.4.0: + version "6.4.0" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233" randomatic@^1.1.3: version "1.1.6" @@ -2545,8 +2559,8 @@ read-pkg@^1.0.0: path-type "^1.0.0" "readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.0.2, readable-stream@^2.2.2: - version "2.2.3" - resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.3.tgz#9cf49463985df016c8ae8813097a9293a9b33729" + version "2.2.6" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.6.tgz#8b43aed76e71483938d12a8d46c6cf1a00b1f816" dependencies: buffer-shims "^1.0.0" core-util-is "~1.0.0" @@ -2603,7 +2617,7 @@ regenerator-runtime@^0.10.0: regex-cache@^0.4.2: version "0.4.3" - resolved "http://registry.npmjs.org/regex-cache/-/regex-cache-0.4.3.tgz#9b1a6c35d4d0dfcef5711ae651e8e9d3d7114145" + resolved "https://registry.yarnpkg.com/regex-cache/-/regex-cache-0.4.3.tgz#9b1a6c35d4d0dfcef5711ae651e8e9d3d7114145" dependencies: is-equal-shallow "^0.1.3" is-primitive "^2.0.0" @@ -2623,17 +2637,17 @@ repeating@^2.0.0: is-finite "^1.0.0" request@^2.69.0, request@^2.79.0: - version "2.79.0" - resolved "https://registry.yarnpkg.com/request/-/request-2.79.0.tgz#4dfe5bf6be8b8cdc37fcf93e04b65577722710de" + version "2.81.0" + resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0" dependencies: aws-sign2 "~0.6.0" aws4 "^1.2.1" - caseless "~0.11.0" + caseless "~0.12.0" combined-stream "~1.0.5" extend "~3.0.0" forever-agent "~0.6.1" form-data "~2.1.1" - har-validator "~2.0.6" + har-validator "~4.2.1" hawk "~3.1.3" http-signature "~1.1.0" is-typedarray "~1.0.0" @@ -2641,10 +2655,12 @@ request@^2.69.0, request@^2.79.0: json-stringify-safe "~5.0.1" mime-types "~2.1.7" oauth-sign "~0.8.1" - qs "~6.3.0" + performance-now "^0.2.0" + qs "~6.4.0" + safe-buffer "^5.0.1" stringstream "~0.0.4" tough-cookie "~2.3.0" - tunnel-agent "~0.4.1" + tunnel-agent "^0.6.0" uuid "^3.0.0" require-directory@^2.1.1: @@ -2671,8 +2687,10 @@ resolve@1.1.7: resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" resolve@^1.1.6, resolve@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.2.0.tgz#9589c3f2f6149d1417a40becc1663db6ec6bc26c" + version "1.3.2" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.3.2.tgz#1f0442c9e0cbb8136e87b9305f932f46c7f28235" + dependencies: + path-parse "^1.0.5" restore-cursor@^1.0.1: version "1.0.1" @@ -2750,8 +2768,8 @@ set-immediate-shim@^1.0.1: resolved "https://registry.yarnpkg.com/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz#4b2b1b27eb808a9f8dcc481a58e5e56f599f3f61" shelljs@^0.7.5: - version "0.7.6" - resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.6.tgz#379cccfb56b91c8601e4793356eb5382924de9ad" + version "0.7.7" + resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.7.tgz#b2f5c77ef97148f4b4f6e22682e10bba8667cff1" dependencies: glob "^7.0.0" interpret "^1.0.0" @@ -2780,10 +2798,10 @@ sntp@1.x.x: hoek "2.x.x" source-map-support@^0.4.2: - version "0.4.11" - resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.11.tgz#647f939978b38535909530885303daf23279f322" + version "0.4.13" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.13.tgz#9782e6f7deb424d5f173327a1879eb46453bdcd4" dependencies: - source-map "^0.5.3" + source-map "^0.5.6" source-map@^0.4.4: version "0.4.4" @@ -2791,7 +2809,7 @@ source-map@^0.4.4: dependencies: amdefine ">=0.0.4" -source-map@^0.5.0, source-map@^0.5.3, source-map@~0.5.1: +source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1: version "0.5.6" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412" @@ -2820,8 +2838,8 @@ sprintf-js@~1.0.2: resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" sshpk@^1.7.0: - version "1.10.2" - resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.10.2.tgz#d5a804ce22695515638e798dbe23273de070a5fa" + version "1.11.0" + resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.11.0.tgz#2d8d5ebb4a6fab28ffba37fa62a90f4a3ea59d77" dependencies: asn1 "~0.2.3" assert-plus "^1.0.0" @@ -3006,9 +3024,11 @@ tryit@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb" -tunnel-agent@~0.4.1: - version "0.4.3" - resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.4.3.tgz#6373db76909fe570e08d73583365ed828a74eeeb" +tunnel-agent@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd" + dependencies: + safe-buffer "^5.0.1" tv4@^1.2.7: version "1.2.7" @@ -3029,10 +3049,9 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" uglify-js@^2.6: - version "2.7.5" - resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.7.5.tgz#4612c0c7baaee2ba7c487de4904ae122079f2ca8" + version "2.8.13" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.13.tgz#d0cdf02f3c661484fac601b7e723207b735a374c" dependencies: - async "~0.2.6" source-map "~0.5.1" uglify-to-browserify "~1.0.0" yargs "~3.10.0" @@ -3121,8 +3140,8 @@ whatwg-encoding@^1.0.1: iconv-lite "0.4.13" whatwg-url@^4.3.0: - version "4.5.0" - resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-4.5.0.tgz#79bb6f0e370a4dda1cbc8f3062a490cf8bbb09ea" + version "4.6.0" + resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-4.6.0.tgz#ef98da442273be04cf9632e176f257d2395a1ae4" dependencies: tr46 "~0.0.3" webidl-conversions "^3.0.0" From 1d61fce1dca99774255a8a9f6d21fe879122e747 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Wed, 15 Mar 2017 09:16:47 -0700 Subject: [PATCH 5/7] use new mixin syntax --- src/mixins/duration.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mixins/duration.js b/src/mixins/duration.js index 9b90b34..5f737c2 100644 --- a/src/mixins/duration.js +++ b/src/mixins/duration.js @@ -9,14 +9,13 @@ export const FLAG = { hasValue: true } -export default class DurationMixin { +export default class Duration { cmd: Command constructor (cmd: Command) { this.cmd = cmd } get duration (): Date { - // this is a little gross but I think needed to cast it to a string let duration = this.cmd.flags.duration return new Date(duration) } From 052a8f1fcffd41584f07b94424093849bc484a44 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Wed, 15 Mar 2017 09:20:50 -0700 Subject: [PATCH 6/7] fix mixin --- src/commands/duration.js | 6 ++++-- src/mixins/duration.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/commands/duration.js b/src/commands/duration.js index 7ca8b96..bfe7ea3 100644 --- a/src/commands/duration.js +++ b/src/commands/duration.js @@ -1,16 +1,18 @@ // @flow import Command from 'cli-engine-command' -import Duration from '../mixins/duration' +import Duration, {DurationFlag} from '../mixins/duration' export default class extends Command { static topic = 'cli' static command = 'duration' static description = 'this is an example command showing duration parsing' + static flags = [DurationFlag] duration = new Duration(this) run () { - this.log(`duration: ${this.duration.toString()}`) + this.log('duration:') + this.inspect(this.duration.value) } } diff --git a/src/mixins/duration.js b/src/mixins/duration.js index 5f737c2..da6ccb1 100644 --- a/src/mixins/duration.js +++ b/src/mixins/duration.js @@ -2,7 +2,7 @@ import type Command from 'cli-engine-command' -export const FLAG = { +export const DurationFlag = { name: 'duration', description: 'a duration', required: true, @@ -15,7 +15,7 @@ export default class Duration { this.cmd = cmd } - get duration (): Date { + get value (): Date { let duration = this.cmd.flags.duration return new Date(duration) } From a73fdd9a2cf46ff1377f667b32f58bde138fe447 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Fri, 17 Mar 2017 21:26:03 -0700 Subject: [PATCH 7/7] use new flag syntax --- package.json | 2 +- src/commands/duration.js | 10 ++++------ src/flags/duration.js | 19 +++++++++++++++++++ src/mixins/duration.js | 22 ---------------------- yarn.lock | 6 +++--- 5 files changed, 27 insertions(+), 32 deletions(-) create mode 100644 src/flags/duration.js delete mode 100644 src/mixins/duration.js diff --git a/package.json b/package.json index fdac133..5bd4d36 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "2.1.0", "author": "Jeff Dickey @dickeyxxxx", "dependencies": { - "cli-engine-command": "2.2.4" + "cli-engine-command": "2.2.5" }, "devDependencies": { "babel-cli": "^6.24.0", diff --git a/src/commands/duration.js b/src/commands/duration.js index bfe7ea3..a1ac8be 100644 --- a/src/commands/duration.js +++ b/src/commands/duration.js @@ -1,18 +1,16 @@ // @flow import Command from 'cli-engine-command' -import Duration, {DurationFlag} from '../mixins/duration' +import DurationFlag from '../flags/duration' export default class extends Command { static topic = 'cli' static command = 'duration' static description = 'this is an example command showing duration parsing' - static flags = [DurationFlag] + static flags = {duration: DurationFlag()} - duration = new Duration(this) - - run () { + async run () { this.log('duration:') - this.inspect(this.duration.value) + this.inspect(this.flags.duration) } } diff --git a/src/flags/duration.js b/src/flags/duration.js new file mode 100644 index 0000000..8d8fa87 --- /dev/null +++ b/src/flags/duration.js @@ -0,0 +1,19 @@ +// @flow + +import type {Flag} from 'cli-engine-command' + +type Options = $Shape> + +export default function DurationFlag (options: Options = {}, env: typeof process.env = process.env): Flag { + const defaultOptions: Options = { + description: 'a duration', + parse: (input) => { + if (!input) { + if (options.required) throw new Error('No org specified') + return + } + return new Date(input) + } + } + return Object.assign(defaultOptions, options) +} diff --git a/src/mixins/duration.js b/src/mixins/duration.js deleted file mode 100644 index da6ccb1..0000000 --- a/src/mixins/duration.js +++ /dev/null @@ -1,22 +0,0 @@ -// @flow - -import type Command from 'cli-engine-command' - -export const DurationFlag = { - name: 'duration', - description: 'a duration', - required: true, - hasValue: true -} - -export default class Duration { - cmd: Command - constructor (cmd: Command) { - this.cmd = cmd - } - - get value (): Date { - let duration = this.cmd.flags.duration - return new Date(duration) - } -} diff --git a/yarn.lock b/yarn.lock index fdb7cd8..d37b445 100644 --- a/yarn.lock +++ b/yarn.lock @@ -576,9 +576,9 @@ cli-cursor@^1.0.1: dependencies: restore-cursor "^1.0.1" -cli-engine-command@2.2.4: - version "2.2.4" - resolved "https://registry.yarnpkg.com/cli-engine-command/-/cli-engine-command-2.2.4.tgz#5fec4faec100a3b7b437e5bc9d8ce543c27f68c5" +cli-engine-command@2.2.5: + version "2.2.5" + resolved "https://registry.yarnpkg.com/cli-engine-command/-/cli-engine-command-2.2.5.tgz#31c4bd2e08bf8ea2a2e4404ae6f07da3f8f41e02" dependencies: ansi-escapes "^1.4.0" cardinal "^1.0.0"