Repository: yargs/yargs (js)

Issue:
Question: Filename appearing next to command in help menu
Just a quick question. I am not sure if this is a NodeJS issue or what, but when I run the example yargs code, I get the following in my terminal:

```
example.js <cmd> [args]

Commands:
  example.js hello [name]  welcome ter yargs!

Options:
  --version  Show version number                                       [boolean]
  --help     Show help                                                 [boolean]
```

In the example, the filename is not next to the command `hello` under the `Commands` section. Just wondering how to get the filename out of that section so that it looks like the one from the example:

```
  Commands:
    hello [name]  welcome ter yargs!

```

Pull request description:
feat: Allow setting scriptName $0
Fixes #1010 #1048 #1065

Patch:
diff --git a/docs/api.md b/docs/api.md
index 85af995..d18d8f9 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -813,6 +813,20 @@ var yargs = require("yargs")(['--info'])
   .argv
 ```
 
+<a name="scriptName"></a>.scriptName($0)
+------------------
+
+Set the name of your script ($0). Default is the base filename executed by node (`process.argv[1]`)
+
+Example:
+
+```js
+var yargs = require("yargs")
+  .scriptName("my-script")
+  .help()
+  .argv
+```
+
 <a name="showHidden"></a>.showHidden()
 -----------------------------------------
 .showHidden([option | boolean])
diff --git a/yargs.js b/yargs.js
index da1a4bd..c2ac0fe 100644
--- a/yargs.js
+++ b/yargs.js
@@ -37,6 +37,11 @@ function Yargs (processArgs, cwd, parentRequire) {
 
   if (!cwd) cwd = process.cwd()
 
+  self.scriptName = function scriptName (scriptName) {
+    self.$0 = scriptName
+    return self
+  }
+
   self.$0 = process.argv
     .slice(0, 2)
     .map((x, i) => {


Test patch:
diff --git a/test/usage.js b/test/usage.js
index 8907e35..6cfad3e 100644
--- a/test/usage.js
+++ b/test/usage.js
@@ -1232,6 +1232,26 @@ describe('usage tests', () => {
     })
   })
 
+  describe('scriptName', () => {
+    it('should display user supplied scriptName', () => {
+      const r = checkUsage(() => yargs(['--help'])
+        .scriptName('custom')
+        .command('command')
+        .parse()
+      )
+      r.logs.join('\n').split(/\n+/).should.deep.equal([
+        'custom [command]',
+        'Commands:',
+        '  custom command',
+        'Options:',
+        '  --help     Show help                                                 [boolean]',
+        '  --version  Show version number                                       [boolean]'
+      ])
+      r.errors.should.have.length(0)
+      r.exit.should.equal(true)
+    })
+  })
+
   it('should succeed when rebase', () => {
     rebase(['home', 'chevex'].join(path.sep), ['home', 'chevex', 'foo', 'bar', 'baz'].join(path.sep)).should.equal(['foo', 'bar', 'baz'].join(path.sep))
     rebase(['home', 'chevex', 'foo', 'bar', 'baz'].join(path.sep), ['home', 'chevex'].join(path.sep)).should.equal(['..', '..', '..'].join(path.sep))