Repository: yargs/yargs
Pull request #1194 (2018-08-06 14:52:35)

Update advanced.md


Patch:
diff --git a/.gitignore b/.gitignore
index 3e4ea0e..f8a81be 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@ node_modules/
 test.js
 coverage
 package-lock.json
+.npmrc
diff --git a/docs/advanced.md b/docs/advanced.md
index ff38c40..67b62f6 100644
--- a/docs/advanced.md
+++ b/docs/advanced.md
@@ -338,7 +338,7 @@ exports.handler = function (argv) {
 ## Building Configurable CLI Apps
 
 One of the goals of yargs has been to examine practices common in the
-JavaScript CLI community, and to make to make it easy to apply these
+JavaScript CLI community, and to make it easy to apply these
 conventions to your own application.
 
 One useful set of conventions that has emerged is around how applications
diff --git a/lib/command.js b/lib/command.js
index bbd986e..ea7aa3d 100644
--- a/lib/command.js
+++ b/lib/command.js
@@ -19,7 +19,8 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
     let aliases = []
     handler = handler || (() => {})
     middlewares = middlewares || []
-    middlewares = globalMiddleware.concat(middlewares)
+    globalMiddleware.push(...middlewares)
+    middlewares = globalMiddleware
     if (Array.isArray(cmd)) {
       aliases = cmd.slice(1)
       cmd = cmd[0]
diff --git a/lib/validation.js b/lib/validation.js
index d72ad52..e9bbb12 100644
--- a/lib/validation.js
+++ b/lib/validation.js
@@ -292,7 +292,7 @@ module.exports = function validation (yargs, usage, y18n) {
           // we default keys to 'undefined' that have been configured, we should not
           // apply conflicting check unless they are a value other than 'undefined'.
           if (value && argv[key] !== undefined && argv[value] !== undefined) {
-            usage.fail(__(`Arguments ${key} and ${value} are mutually exclusive`))
+            usage.fail(__('Arguments %s and %s are mutually exclusive', key, value))
           }
         })
       }
diff --git a/locales/pirate.json b/locales/pirate.json
index 1f4e19e..dcb5cb7 100644
--- a/locales/pirate.json
+++ b/locales/pirate.json
@@ -8,5 +8,6 @@
     "other": "Ye be havin' to set the followin' arguments land lubber: %s"
   },
   "Show help": "Parlay this here code of conduct",
-  "Show version number": "'Tis the version ye be askin' fer"
+  "Show version number": "'Tis the version ye be askin' fer",
+  "Arguments %s and %s are mutually exclusive" : "Yon scurvy dogs %s and %s be as bad as rum and a prudish wench"
 }


Test patch:
diff --git a/test/middleware.js b/test/middleware.js
index 764b1b0..0423768 100644
--- a/test/middleware.js
+++ b/test/middleware.js
@@ -53,4 +53,31 @@ describe('middleware', () => {
       .exitProcess(false) // defaults to true.
       .parse()
   })
+
+  it('should be able to register middleware regardless of when middleware is called', function (done) {
+    yargs(['mw'])
+      .middleware([
+        function (argv) {
+          argv.mw1 = 'mw1'
+        }
+      ])
+      .command(
+        'mw',
+        'adds func list to middleware',
+        function () {},
+        function (argv) {
+          // we should get the argv filled with data from the middleware
+          argv.mw1.should.equal('mw1')
+          argv.mw2.should.equal('mw2')
+          return done()
+        }
+      )
+      .middleware([
+        function (argv) {
+          argv.mw2 = 'mw2'
+        }
+      ])
+      .exitProcess(false) // defaults to true.
+      .parse()
+  })
 })
diff --git a/test/validation.js b/test/validation.js
index c9d0593..788ca70 100644
--- a/test/validation.js
+++ b/test/validation.js
@@ -3,7 +3,7 @@
 
 const checkUsage = require('./helpers/utils').checkOutput
 const expect = require('chai').expect
-const yargs = require('../')
+let yargs = require('../')
 
 require('chai').should()
 
@@ -285,6 +285,28 @@ describe('validation tests', () => {
         })
         .parse()
     })
+
+    function loadLocale (locale) {
+      delete require.cache[require.resolve('../')]
+      delete require.cache[require.resolve('os-locale')]
+      yargs = require('../')
+      process.env.LC_ALL = locale
+    }
+
+    it('should use appropriate translation', done => {
+      loadLocale('pirate')
+      try {
+        yargs(['-f', '-b'])
+          .conflicts('f', 'b')
+          .fail(msg => {
+            msg.should.equal('Yon scurvy dogs f and b be as bad as rum and a prudish wench')
+            return done()
+          })
+          .parse()
+      } finally {
+        loadLocale('en_US.UTF-8')
+      }
+    })
   })
 
   describe('demand', () => {