Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't alter the user supplied script name #1383

Merged
merged 1 commit into from Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/usage.js
Expand Up @@ -151,7 +151,7 @@ module.exports = function usage (yargs, y18n) {
normalizeAliases()

// handle old demanded API
const base$0 = path.basename(yargs.$0)
const base$0 = yargs.customScriptName ? yargs.$0 : path.basename(yargs.$0)
const demandedOptions = yargs.getDemandedOptions()
const demandedCommands = yargs.getDemandedCommands()
const groups = yargs.getGroups()
Expand Down
18 changes: 18 additions & 0 deletions test/usage.js
Expand Up @@ -1250,6 +1250,24 @@ describe('usage tests', () => {
r.errors.should.have.length(0)
r.exit.should.equal(true)
})

it('should not alter the 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', () => {
Expand Down
3 changes: 2 additions & 1 deletion yargs.js
Expand Up @@ -37,7 +37,8 @@ function Yargs (processArgs, cwd, parentRequire) {

if (!cwd) cwd = process.cwd()

self.scriptName = function scriptName (scriptName) {
self.scriptName = function (scriptName) {
self.customScriptName = true
self.$0 = scriptName
return self
}
Expand Down