Repository: yargs/yargs (js)

Issue:
global options are not affected by environment variables when using sub commands
When declaring a sub command that also has its own options, environment variables no longer affect global options. Is my configuration wrong?

````javascript
var argv = require('yargs')
  .env('MY_PROGRAM')
  .options({
    'f': {
      alias: 'fruit-thing',
      type: 'boolean',
      global: true,
    },
  })
  .command('cmd', '', function(yargs) {
    return yargs.options({
      'sub': {
        type: 'boolean',
      }
    });
  })
  .argv
console.log(argv);
````
I would expect this to print `{fruitThing: true}` but it does not:
````
MY_PROGRAM_FRUIT_THING=true node script.js cmd
````
However, if I comment out `yargs.options(...)` in the sub command, it works.

This is only limited to environment variables. The following works as expected:
````
node script.js --fruit-thing cmd
````

Pull request description:
feat: apply .env() globally
Fixes #486.

This means that a configured `envPrefix` will not be reset for nested commands.

This could potentially be considered a breaking change since env vars that used to be ignored for the execution of command handlers may no longer be ignored. 😮 Otherwise, this could be considered a fix. 😕 

Patch:
diff --git a/locales/zh.json b/locales/zh.json
deleted file mode 100644
index b25c7b9..0000000
--- a/locales/zh.json
+++ /dev/null
@@ -1,37 +0,0 @@
-{
-  "Commands:": "命令：",
-  "Options:": "选项：",
-  "Examples:": "示例：",
-  "boolean": "布尔",
-  "count": "计数",
-  "string": "字符串",
-  "number": "数字",
-  "array": "数组",
-  "required": "必需",
-  "default:": "默认值:",
-  "choices:": "可选值:",
-  "generated-value": "生成的值",
-  "Not enough non-option arguments: got %s, need at least %s": "缺少 non-option 参数：传入了 %s 个, 至少需要 %s 个",
-  "Too many non-option arguments: got %s, maximum of %s": "non-option 参数过多：传入了 %s 个, 最大允许 %s 个",
-  "Missing argument value: %s": {
-    "one": "没有给此选项指定值：%s",
-    "other": "没有给这些选项指定值：%s"
-  },
-  "Missing required argument: %s": {
-    "one": "缺少必须的选项：%s",
-    "other": "缺少这些必须的选项：%s"
-  },
-  "Unknown argument: %s": {
-    "one": "无法识别的选项：%s",
-    "other": "无法识别这些选项：%s"
-  },
-  "Invalid values:": "无效的选项值：",
-  "Argument: %s, Given: %s, Choices: %s": "选项名称: %s, 传入的值: %s, 可选的值：%s",
-  "Argument check failed: %s": "选项值验证失败：%s",
-  "Implications failed:": "缺少依赖的选项：",
-  "Not enough arguments following: %s": "没有提供足够的值给此选项：%s",
-  "Invalid JSON config file: %s": "无效的 JSON 配置文件：%s",
-  "Path to JSON config file": "JSON 配置文件的路径",
-  "Show help": "显示帮助信息",
-  "Show version number": "显示版本号"
-}
diff --git a/yargs.js b/yargs.js
index 3377b1d..90e579b 100644
--- a/yargs.js
+++ b/yargs.js
@@ -113,7 +113,7 @@ function Yargs (processArgs, cwd, parentRequire) {
       })
     })
 
-    tmpOptions.envPrefix = undefined
+    tmpOptions.envPrefix = options.envPrefix
     options = tmpOptions
 
     // if this is the first time being executed, create


Test patch:
diff --git a/test/command.js b/test/command.js
index 3d0888a..7ca7d55 100644
--- a/test/command.js
+++ b/test/command.js
@@ -547,6 +547,23 @@ describe('Command', function () {
     })
   })
 
+  // see: https://github.com/yargs/yargs/pull/553
+  it('preserves top-level envPrefix', function () {
+    process.env.FUN_DIP_STICK = 'yummy'
+    process.env.FUN_DIP_POWDER = 'true'
+    yargs('eat')
+      .env('FUN_DIP')
+      .global('stick') // this does not actually need to be global
+      .command('eat', 'Adult supervision recommended', function (yargs) {
+        return yargs.boolean('powder').exitProcess(false)
+      }, function (argv) {
+        argv.should.have.property('powder').and.be.true
+        argv.should.have.property('stick').and.equal('yummy')
+      })
+      .exitProcess(false)
+      .argv
+  })
+
   // addresses https://github.com/yargs/yargs/issues/514.
   it('respects order of positional arguments when matching commands', function () {
     var output = []
diff --git a/test/yargs.js b/test/yargs.js
index e491d24..b50ae7a 100644
--- a/test/yargs.js
+++ b/test/yargs.js
@@ -226,7 +226,7 @@ describe('yargs dsl tests', function () {
         normalize: [],
         number: [],
         config: {},
-        envPrefix: undefined,
+        envPrefix: 'YARGS', // preserved as global
         global: ['help'],
         demanded: {}
       }