Repository: yargs/yargs (js)

Issue:
exception thrown when yargs.parsed.newAliases is undefined
Found something of an issue when using `yargs.showHelp()`
[L761](https://github.com/yargs/yargs/blob/master/yargs.js#L761)

it seems that when `self._parseArgs(processArgs)` is called, it is not saving the results to `self.parsed`

if you put a breakpoint on this line: [L1012](https://github.com/yargs/yargs/blob/master/yargs.js#L1012), you will see that the `self.parsed` property contains the appropriate items.

however, after this function is done, on [L762](https://github.com/yargs/yargs/blob/master/yargs.js#L762),
`self.parsed` is set back to `false` instead of an object. this leads to their being a parse error:

`TypeError: Cannot convert undefined or null to object`
`.concat(Object.keys(yargs.parsed.newAliases) || [])`

under function: `usage.showHelp(` [L240](https://github.com/yargs/yargs/blob/master/lib/usage.js#L240)

Thanks! 👍 


Pull request description:
fix: properties accessed on singleton now reflect current state of instance
`singletonify()` used to set `Argv`'s properties to `inst`'s properties values _at the time of `Argv`'s last call_.

So `Argv`'s properties and the `inst`'s ones could diverge afterwards, such as `parsed` after a call to `parse()`, still being `false` in `Argv.parsed`, not in `inst.parse`.

`singletonify()` now adds setters to `Argv` instead, looking for the value of the corresponding property in `inst` _at the time the property is used_.

Patch:
diff --git a/README.md b/README.md
index 6b7d096..2d1ab3b 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,7 @@
 <p align="center">
   <b >Yargs be a node.js library fer hearties tryin' ter parse optstrings</b>
 </p>
+
 <br>
 
 [![Build Status][travis-image]][travis-url]
@@ -102,6 +103,7 @@ Having problems? want to contribute? join our [community slack](http://devtoolsc
   * [Numbers](/docs/tricks.md#numbers)
   * [Arrays](/docs/tricks.md#arrays)
   * [Objects](/docs/tricks.md#objects)
+  * [Quotes](/docs/tricks.md#quotes)
 * [Advanced Topics](/docs/advanced.md)
   * [Composing Your App Using Commands](/docs/advanced.md#commands)
   * [Building Configurable CLI Apps](/docs/advanced.md#configuration)
diff --git a/docs/tricks.md b/docs/tricks.md
index 735cb55..d43cb62 100644
--- a/docs/tricks.md
+++ b/docs/tricks.md
@@ -55,3 +55,27 @@ This lets you organize arguments into nested objects.
     { _: [],
       foo: { bar: { baz: 33 }, quux: 5 },
       '$0': 'examples/reflect.js' }
+
+<a name="quotes"></a>
+
+Quotes
+------------
+
+When you use string arguments that include dashes (`-`), those will be seen as a separate option by the shell instead of part of the string. The problem is that shells like bash tend to strip quotes. The solution for this is to wrap the string in two sets of quotes.
+
+Use double quotes inside single quotes.
+
+```
+$ node examples/reflect.js --foo '"--hello -x=yes -v"'
+{ _: [], foo: '--hello -x=yes -v',
+  '$0': 'examples/reflect.js' }
+```
+
+Use escaped double quotes inside double quotes.
+
+```
+$ node examples/reflect.js --foo "\"--hello -x=yes -v\""
+{ _: [], foo: '--hello -x=yes -v',
+  '$0': 'examples/reflect.js' }
+```
+
diff --git a/index.js b/index.js
index dfed54b..25bde57 100644
--- a/index.js
+++ b/index.js
@@ -25,8 +25,10 @@ function singletonify (inst) {
   Object.keys(inst).forEach((key) => {
     if (key === 'argv') {
       Argv.__defineGetter__(key, inst.__lookupGetter__(key))
+    } else if (typeof inst[key] === 'function') {
+      Argv[key] = inst[key].bind(inst)
     } else {
-      Argv[key] = typeof inst[key] === 'function' ? inst[key].bind(inst) : inst[key]
+      Argv.__defineGetter__(key, () => inst[key])
     }
   })
 }


Test patch:
diff --git a/test/yargs.js b/test/yargs.js
index 20f1058..66c5bf8 100644
--- a/test/yargs.js
+++ b/test/yargs.js
@@ -837,6 +837,17 @@ describe('yargs dsl tests', () => {
     })
   })
 
+  describe('parsed', () => {
+    it('should be false before parsing', () => {
+      yargs.parsed.should.equal(false)
+    })
+
+    it('should not be false after parsing', () => {
+      yargs.parse()
+      yargs.parsed.should.not.equal(false)
+    })
+  })
+
   // yargs.parse(['foo', '--bar'], function (err, argv, output) {}
   context('function passed as second argument to parse', () => {
     it('does not print to stdout', () => {