Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR-AN-01: Global Middleware feature. #1119

Merged
merged 10 commits into from May 1, 2018

Conversation

Projects
None yet
2 participants
@aorinevo
Copy link
Member

commented Apr 27, 2018

PR-AN-03: Update API readme.

PR-AN-01: Fix tests.

PR-AN-01: Remove param defaults for Node 4 comp.

PR-AN-01: Remove spread operator for Node 4 comp.

PR-AN-01: Add unit tests for middleware.

PR-AN-01: Bind this to middleware for chaining.

@bcoe
Copy link
Member

left a comment

a couple minor tweaks; love this feature idea.

.command('myCommand', 'some command', {}, function(argv){
console.log('Running myCommand!');
})
.middleware([mwFunc1, mwFunc2]).argv;

This comment has been minimized.

Copy link
@bcoe

bcoe Apr 27, 2018

Member

can I pass in a single function, rather than an array?

This comment has been minimized.

Copy link
@aorinevo

aorinevo Apr 27, 2018

Author Member

Yea, it can either be a single function or a list of functions.

globalMiddleware.should.have.lengthOf(2)
})

it('should add a single callback to global middleware', () => {

This comment has been minimized.

Copy link
@bcoe

bcoe Apr 27, 2018

Member

mind adding one functional test that demonstrates global middleware being applied? either in this file, or perhaps in the yargs.js test file.

This comment has been minimized.

Copy link
@aorinevo

aorinevo Apr 30, 2018

Author Member

Added functional test below.

@aorinevo aorinevo force-pushed the aorinevo:FEATURE/PR-AN-01_master_AN_global_mw branch from 12719e5 to 07e0994 Apr 27, 2018

@aorinevo aorinevo changed the title PR-AN-01: Global Middleware feature. WIP: PR-AN-01: Global Middleware feature. Apr 27, 2018

@aorinevo aorinevo changed the title WIP: PR-AN-01: Global Middleware feature. PR-AN-01: Global Middleware feature. Apr 29, 2018

docs/api.md Outdated

Define global middleware functions to be called first, in list order, for all cli command.

The `callbacks` parameter can be a function or a list of functions.

This comment has been minimized.

Copy link
@aorinevo

aorinevo Apr 30, 2018

Author Member

Add a note that each function gets passed a reference to argv.

globalMiddleware.should.have.lengthOf(2)
})

it('should add a single callback to global middleware', () => {

This comment has been minimized.

Copy link
@aorinevo

aorinevo Apr 30, 2018

Author Member

Added functional test below.

@bcoe

bcoe approved these changes May 1, 2018

@bcoe

This comment has been minimized.

Copy link
Member

commented May 1, 2018

@aorinevo great work 👍 love this feature.

@bcoe bcoe merged commit 9d71ac7 into yargs:master May 1, 2018

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.2%) to 100.0%
Details
@bcoe

This comment has been minimized.

Copy link
Member

commented Jun 26, 2018

@aorinevo this feature is now available on npm i yargs@next, mind giving it one more try and letting me know if things work as expected?

If the redux work goes smooth, I think this will probably end up being yargs@13.x 👍

@aorinevo aorinevo deleted the aorinevo:FEATURE/PR-AN-01_master_AN_global_mw branch Jun 26, 2018

eliperelman added a commit to neutrinojs/neutrino that referenced this pull request Jul 2, 2018

Update dependency yargs to v12 (#969)
This Pull Request updates dependency [yargs](https://github.com/yargs/yargs) from `^11.0.0` to `^12.0.0`



<details>
<summary>Release Notes</summary>

### [`v12.0.1`](https://github.com/yargs/yargs/blob/master/CHANGELOG.md#&#8203;1201httpsgithubcomyargsyargscomparev1200v1201-2018-06-29)
[Compare Source](yargs/yargs@v12.0.0...v12.0.1)
#### [12.0.1](yargs/yargs@v12.0.0...v12.0.1) (2018-06-29)

---

### [`v12.0.0`](https://github.com/yargs/yargs/blob/master/CHANGELOG.md#&#8203;1200httpsgithubcomyargsyargscomparev1110v1200-2018-06-26)
[Compare Source](yargs/yargs@v11.1.0...v12.0.0)
##### Bug Fixes

* .argv and .parse() now invoke identical code path ([#&#8203;1126](`yargs/yargs#1126)) ([f13ebf4](yargs/yargs@f13ebf4))
* remove the trailing white spaces from the help output ([#&#8203;1090](`yargs/yargs#1090)) ([3f0746c](yargs/yargs@3f0746c))
* **completion:** Avoid default command and recommendations during completion ([#&#8203;1123](`yargs/yargs#1123)) ([036e7c5](yargs/yargs@036e7c5))
##### Chores

* test Node.js 6, 8 and 10 ([#&#8203;1160](`yargs/yargs#1160)) ([84f9d2b](yargs/yargs@84f9d2b))
* upgrade to version of yargs-parser that does not populate value for unset boolean ([#&#8203;1104](`yargs/yargs#1104)) ([d4705f4](yargs/yargs@d4705f4))
##### Features

* add support for global middleware, useful for shared tasks like metrics ([#&#8203;1119](`yargs/yargs#1119)) ([9d71ac7](yargs/yargs@9d71ac7))
* allow setting scriptName $0 ([#&#8203;1143](`yargs/yargs#1143)) ([a2f2eae](yargs/yargs@a2f2eae))
* remove `setPlaceholderKeys` ([#&#8203;1105](`yargs/yargs#1105)) ([6ee2c82](yargs/yargs@6ee2c82))
##### BREAKING CHANGES

* Options absent from `argv` (not set via CLI argument) are now absent from the parsed result object rather than being set with `undefined`
* drop Node 4 from testing matrix, such that we'll gradually start drifting away from supporting Node 4.
* yargs-parser does not populate 'false' when boolean flag is not passed
* tests that assert against help output will need to be updated

---

</details>




---

This PR has been generated by [Renovate Bot](https://renovatebot.com).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.