Skip to content

Commit

Permalink
feat: replace /bin/bash with file basename (yargs#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
lostintangent authored and bcoe committed Oct 17, 2017
1 parent 5a9c986 commit 20bb99b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 52 deletions.
7 changes: 4 additions & 3 deletions lib/usage.js
Expand Up @@ -3,6 +3,7 @@
// failures, etc. keeps logging in one place.
const stringWidth = require('string-width')
const objFilter = require('./obj-filter')
const path = require('path')
const setBlocking = require('set-blocking')
const YError = require('./yerror')

Expand Down Expand Up @@ -165,7 +166,7 @@ module.exports = function usage (yargs, y18n) {

// the usage string.
if (usages.length && !usageDisabled) {
const u = self.getUsage().replace(/\$0/g, yargs.$0)
const u = self.getUsage().replace(/\$0/g, path.basename(yargs.$0))
ui.div(`${u}`)
}

Expand Down Expand Up @@ -275,7 +276,7 @@ module.exports = function usage (yargs, y18n) {
ui.div(__('Examples:'))

examples.forEach((example) => {
example[0] = example[0].replace(/\$0/g, yargs.$0)
example[0] = example[0].replace(/\$0/g, path.basename(yargs.$0))
})

examples.forEach((example) => {
Expand Down Expand Up @@ -304,7 +305,7 @@ module.exports = function usage (yargs, y18n) {

// the usage string.
if (epilog) {
const e = epilog.replace(/\$0/g, yargs.$0)
const e = epilog.replace(/\$0/g, path.basename(yargs.$0))
ui.div(`${e}\n`)
}

Expand Down
8 changes: 4 additions & 4 deletions test/command.js
Expand Up @@ -532,7 +532,7 @@ describe('Command', () => {
r.should.have.property('errors').with.length(0)
r.should.have.property('logs')
r.logs[0].split(/\n+/).should.deep.equal([
'./command dream [command] [opts]',
'command dream [command] [opts]',
'Commands:',
' of-memory <memory> Dream about a specific memory',
' within-a-dream [command] [opts] Dream within a dream',
Expand Down Expand Up @@ -604,7 +604,7 @@ describe('Command', () => {
r.should.have.property('errors').with.length(0)
r.should.have.property('logs')
r.logs.join('\n').split(/\n+/).should.deep.equal([
'./command cyclic',
'command cyclic',
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
Expand Down Expand Up @@ -674,7 +674,7 @@ describe('Command', () => {
.argv, [ './command' ])

const expectedCmd = [
'./command cmd <sub>',
'command cmd <sub>',
'Commands:',
' sub Run the subcommand',
'Options:',
Expand All @@ -684,7 +684,7 @@ describe('Command', () => {
]

const expectedSub = [
'./command cmd sub',
'command cmd sub',
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
Expand Down

0 comments on commit 20bb99b

Please sign in to comment.