Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: yargs/yargs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v12.0.2
Choose a base ref
...
head repository: yargs/yargs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v12.0.4
Choose a head ref
  • 14 commits
  • 14 files changed
  • 10 contributors

Commits on Sep 16, 2018

  1. fix: accept single function for middleware

    * Fixed type check in .middleware() method
    
    `if (typeof callback === 'object')` should be `if (typeof callback === 'function')`
    
    See Issue #1214 for details
    
    * middewareFactory accepts a function, not an object
    
    According to [the docs for the `.middleware()` method](http://yargs.js.org/docs/#api-middlewarecallbacks):
    
    > The `callbacks` parameter can be a function or a list of functions
    
    See Issue #1214 for more details
    
    * Added/Updated middleware tests
    
    I added a new test to verify that the `.middleware()` method works when a single function is passed, rather than an array of functions.
    
    Also enhanced an existing test to ensure that _all_ middleware is run before commands, regardless of whether it was added as an array of functions or a single function.
    JamesMessinger authored and aorinevo committed Sep 16, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    bigdaz Daz DeBoer
    Copy the full SHA
    66fd6f7 View commit details

Commits on Oct 6, 2018

  1. Copy the full SHA
    3a258bb View commit details
  2. Copy the full SHA
    da54028 View commit details
  3. Copy the full SHA
    a458fa4 View commit details
  4. Copy the full SHA
    d422eb5 View commit details
  5. Copy the full SHA
    8e3a70f View commit details
  6. Copy the full SHA
    567820b View commit details
  7. chore: update yargs-parser dependency

    Benjamin committed Oct 6, 2018
    Copy the full SHA
    e99e9ae View commit details
  8. chore(release): 12.0.3

    Benjamin committed Oct 6, 2018
    Copy the full SHA
    d72dec1 View commit details

Commits on Oct 11, 2018

  1. test:💥 something amazing is in the works 💥 (#1225)

    * add windows to the travis ci config
    
    * a newline for a new build
    
    * we don't need that newline!
    joshk authored and bcoe committed Oct 11, 2018
    Copy the full SHA
    0e9bb01 View commit details

Commits on Nov 5, 2018

  1. docs: fix sublist indentation (#1238)

    localstatic authored and bcoe committed Nov 5, 2018
    Copy the full SHA
    842b8b2 View commit details
  2. Copy the full SHA
    128f322 View commit details

Commits on Nov 10, 2018

  1. fix: don't load config when processing positionals

    Benjamin Coe committed Nov 10, 2018
    Copy the full SHA
    5d0dc92 View commit details
  2. chore(release): 12.0.4

    Benjamin Coe committed Nov 10, 2018
    Copy the full SHA
    dd4923d View commit details
Showing with 244 additions and 80 deletions.
  1. +8 −6 .travis.yml
  2. +24 −0 CHANGELOG.md
  3. +0 −38 appveyor.yml
  4. +5 −5 contributing.md
  5. +1 −0 lib/command.js
  6. +1 −1 lib/middleware.js
  7. +10 −10 lib/usage.js
  8. +1 −1 locales/nb.json
  9. +2 −2 locales/nn.json
  10. +11 −5 package.json
  11. +25 −0 test/command.js
  12. +32 −7 test/middleware.js
  13. +115 −0 test/usage.js
  14. +9 −5 yargs.js
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
language: node_js

node_js:
- "6"
- "8"
- "10"
- "node"

os:
- linux
- osx

after_success: npm run coverage
- windows

cache:
directories:
- "node_modules"

node_js:
- "6"
- "8"
- "10"
after_success: if [[ "$TRAVIS_OS_NAME" != 'windows' ]]; then npm run coverage; fi
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,30 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="12.0.4"></a>
## [12.0.4](https://github.com/yargs/yargs/compare/v12.0.3...v12.0.4) (2018-11-10)


### Bug Fixes

* don't load config when processing positionals ([5d0dc92](https://github.com/yargs/yargs/commit/5d0dc92))



<a name="12.0.3"></a>
## [12.0.3](https://github.com/yargs/yargs/compare/v12.0.2...v12.0.3) (2018-10-06)


### Bug Fixes

* $0 contains first arg in bundled electron apps ([#1206](https://github.com/yargs/yargs/issues/1206)) ([567820b](https://github.com/yargs/yargs/commit/567820b))
* accept single function for middleware ([66fd6f7](https://github.com/yargs/yargs/commit/66fd6f7)), closes [#1214](https://github.com/yargs/yargs/issues/1214) [#1214](https://github.com/yargs/yargs/issues/1214)
* hide `hidden` options from help output even if they are in a group ([#1221](https://github.com/yargs/yargs/issues/1221)) ([da54028](https://github.com/yargs/yargs/commit/da54028))
* improve Norwegian Bokmål translations ([#1208](https://github.com/yargs/yargs/issues/1208)) ([a458fa4](https://github.com/yargs/yargs/commit/a458fa4))
* improve Norwegian Nynorsk translations ([#1207](https://github.com/yargs/yargs/issues/1207)) ([d422eb5](https://github.com/yargs/yargs/commit/d422eb5))



<a name="12.0.2"></a>
## [12.0.2](https://github.com/yargs/yargs/compare/v12.0.1...v12.0.2) (2018-09-04)

38 changes: 0 additions & 38 deletions appveyor.yml

This file was deleted.

10 changes: 5 additions & 5 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -9,10 +9,10 @@ Me hearties, we would love to have you contribute to yargs!
to help solve:
* it's usually best to get some feedback before proceeding to write code.
3. fork the yargs repo, and clone it to your computer:
* GitHub has [great documentation](https://help.github.com/articles/using-pull-requests/) regarding writing your first pull request.
* GitHub has [great documentation](https://help.github.com/articles/using-pull-requests/) regarding writing your first pull request.
4. make sure that you write unit-test for any code that you write for yargs:
* we use the [standard](https://github.com/feross/standard) coding style,
which will validate your style when you run tests.
* look through our extensive test suite in `/test` to get an idea for how
to write unit-tests for this codebase.
* we use the [standard](https://github.com/feross/standard) coding style,
which will validate your style when you run tests.
* look through our extensive test suite in `/test` to get an idea for how
to write unit-tests for this codebase.
5. make sure you are comfortable with the Code of Conduct outlined below.
1 change: 1 addition & 0 deletions lib/command.js
Original file line number Diff line number Diff line change
@@ -331,6 +331,7 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
options.default = Object.assign(parseOptions.default, options.default)
options.alias = Object.assign(parseOptions.alias, options.alias)
options.array = options.array.concat(parseOptions.array)
delete options.config // don't load config when processing positionals.

const unparsed = []
Object.keys(positionalMap).forEach((key) => {
2 changes: 1 addition & 1 deletion lib/middleware.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ module.exports = function (globalMiddleware, context) {
return function (callback) {
if (Array.isArray(callback)) {
Array.prototype.push.apply(globalMiddleware, callback)
} else if (typeof callback === 'object') {
} else if (typeof callback === 'function') {
globalMiddleware.push(callback)
}
return context
20 changes: 10 additions & 10 deletions lib/usage.js
Original file line number Diff line number Diff line change
@@ -161,13 +161,7 @@ module.exports = function usage (yargs, y18n) {
keys = keys.concat(Object.keys(demandedOptions))
keys = keys.concat(Object.keys(demandedCommands))
keys = keys.concat(Object.keys(options.default))
keys = keys.filter(key => {
if (options.hiddenOptions.indexOf(key) < 0) {
return true
} else if (yargs.parsed.argv[options.showHiddenOpt]) {
return true
}
})
keys = keys.filter(filterHiddenOptions)
keys = Object.keys(keys.reduce((acc, key) => {
if (key !== '_') acc[key] = true
return acc
@@ -251,18 +245,20 @@ module.exports = function usage (yargs, y18n) {
Object.keys(groups).forEach((groupName) => {
if (!groups[groupName].length) return

ui.div(__(groupName))

// if we've grouped the key 'f', but 'f' aliases 'foobar',
// normalizedKeys should contain only 'foobar'.
const normalizedKeys = groups[groupName].map((key) => {
const normalizedKeys = groups[groupName].filter(filterHiddenOptions).map((key) => {
if (~aliasKeys.indexOf(key)) return key
for (let i = 0, aliasKey; (aliasKey = aliasKeys[i]) !== undefined; i++) {
if (~(options.alias[aliasKey] || []).indexOf(key)) return aliasKey
}
return key
})

if (normalizedKeys.length < 1) return

ui.div(__(groupName))

// actually generate the switches string --foo, -f, --bar.
const switches = normalizedKeys.reduce((acc, key) => {
acc[key] = [ key ].concat(options.alias[key] || [])
@@ -420,6 +416,10 @@ module.exports = function usage (yargs, y18n) {
return groupedKeys
}

function filterHiddenOptions (key) {
return yargs.getOptions().hiddenOptions.indexOf(key) < 0 || yargs.parsed.argv[yargs.getOptions().showHiddenOpt]
}

self.showHelp = (level) => {
const logger = yargs._getLoggerInstance()
if (!level) level = 'error'
2 changes: 1 addition & 1 deletion locales/nb.json
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
},
"Invalid values:": "Ugyldige verdier:",
"Argument: %s, Given: %s, Choices: %s": "Argument: %s, Gitt: %s, Valg: %s",
"Argument check failed: %s": "Argument sjekk mislyktes: %s",
"Argument check failed: %s": "Argumentsjekk mislyktes: %s",
"Implications failed:": "Konsekvensene mislyktes:",
"Not enough arguments following: %s": "Ikke nok følgende argumenter: %s",
"Invalid JSON config file: %s": "Ugyldig JSON konfigurasjonsfil: %s",
4 changes: 2 additions & 2 deletions locales/nn.json
Original file line number Diff line number Diff line change
@@ -29,9 +29,9 @@
},
"Invalid values:": "Ugyldige verdiar:",
"Argument: %s, Given: %s, Choices: %s": "Argument: %s, Gjeve: %s, Val: %s",
"Argument check failed: %s": "Argument sjekk mislukkast: %s",
"Argument check failed: %s": "Argumentsjekk mislukkast: %s",
"Implications failed:": "Konsekvensane mislukkast:",
"Not enough arguments following: %s": "Ikkje nok fylgande argument: %s",
"Not enough arguments following: %s": "Ikkje nok fylgjande argument: %s",
"Invalid JSON config file: %s": "Ugyldig JSON konfigurasjonsfil: %s",
"Path to JSON config file": "Bane til JSON konfigurasjonsfil",
"Show help": "Vis hjelp",
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"name": "yargs",
"version": "12.0.2",
"version": "12.0.4",
"description": "yargs the modern, pirate-themed, successor to optimist.",
"main": "./index.js",
"contributors": [
{
"name": "Yargs Contributors",
"url": "https://github.com/yargs/yargs/graphs/contributors"
}
],
"files": [
"index.js",
"yargs.js",
@@ -13,7 +19,7 @@
],
"dependencies": {
"cliui": "^4.0.0",
"decamelize": "^2.0.0",
"decamelize": "^1.2.0",
"find-up": "^3.0.0",
"get-caller-file": "^1.0.1",
"os-locale": "^3.0.0",
@@ -23,7 +29,7 @@
"string-width": "^2.0.0",
"which-module": "^2.0.0",
"y18n": "^3.2.1 || ^4.0.0",
"yargs-parser": "^10.1.0"
"yargs-parser": "^11.1.0"
},
"devDependencies": {
"chai": "^4.1.2",
@@ -49,9 +55,9 @@
},
"repository": {
"type": "git",
"url": "http://github.com/yargs/yargs.git"
"url": "https://github.com/yargs/yargs.git"
},
"homepage": "http://yargs.js.org/",
"homepage": "https://yargs.js.org/",
"standard": {
"ignore": [
"**/example/**"
25 changes: 25 additions & 0 deletions test/command.js
Original file line number Diff line number Diff line change
@@ -110,6 +110,31 @@ describe('Command', () => {
argv.file.should.equal('foo.js')
argv.reporter.should.equal('html')
})

// bug reported by @boneskull during mocha migration.
it('does not load config twice when command executed', () => {
let parseCount = 0
yargs('cmd --config=.foo.json')
.command(
'$0 [foo..]',
'does a thing',
yargs =>
yargs
.option('config', {
default: '.foo.json'
})
.positional('foo', {
description: 'bar'
})
.config('config', filepath => {
parseCount++
return {}
}),
argv => {}
)
.parse()
parseCount.should.equal(1)
})
})

describe('variadic', () => {
39 changes: 32 additions & 7 deletions test/middleware.js
Original file line number Diff line number Diff line change
@@ -24,11 +24,30 @@ describe('middleware', () => {
it('should add a single callback to global middleware', () => {
const globalMiddleware = []

middlewareFactory(globalMiddleware)({})
middlewareFactory(globalMiddleware)(function () {})

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

it('runs the middleware before reaching the handler', function (done) {
yargs(['mw'])
.middleware(function (argv) {
argv.mw = 'mw'
})
.command(
'mw',
'adds func to middleware',
function () {},
function (argv) {
// we should get the argv filled with data from the middleware
argv.mw.should.equal('mw')
return done()
}
)
.exitProcess(false) // defaults to true.
.parse()
})

it('runs all middleware before reaching the handler', function (done) {
yargs(['mw'])
.middleware([
@@ -56,11 +75,9 @@ describe('middleware', () => {

it('should be able to register middleware regardless of when middleware is called', function (done) {
yargs(['mw'])
.middleware([
function (argv) {
argv.mw1 = 'mw1'
}
])
.middleware(function (argv) {
argv.mw1 = 'mw1'
})
.command(
'mw',
'adds func list to middleware',
@@ -69,12 +86,20 @@ describe('middleware', () => {
// we should get the argv filled with data from the middleware
argv.mw1.should.equal('mw1')
argv.mw2.should.equal('mw2')
argv.mw3.should.equal('mw3')
argv.mw4.should.equal('mw4')
return done()
}
)
.middleware(function (argv) {
argv.mw2 = 'mw2'
})
.middleware([
function (argv) {
argv.mw2 = 'mw2'
argv.mw3 = 'mw3'
},
function (argv) {
argv.mw4 = 'mw4'
}
])
.exitProcess(false) // defaults to true.
Loading