mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-31 19:18:19 -05:00
fix: execution of shell commands that have -h/--help option
This commit is contained in:
5
.changeset/shy-humans-arrive.md
Normal file
5
.changeset/shy-humans-arrive.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/parse-cli-args": patch
|
||||
---
|
||||
|
||||
The `--help` option should not convert the command to `help` if the command is unknown. So `pnpm eslint -h` is not parsed as `pnpm help eslint`.
|
||||
@@ -48,16 +48,6 @@ export default async function parseCliArgs (
|
||||
inputArgv,
|
||||
0
|
||||
)
|
||||
if (noptExploratoryResults['help']) {
|
||||
return {
|
||||
argv: noptExploratoryResults.argv,
|
||||
cmd: 'help',
|
||||
options: {},
|
||||
params: noptExploratoryResults.argv.remain,
|
||||
unknownOptions: new Map(),
|
||||
fallbackCommandUsed: false,
|
||||
}
|
||||
}
|
||||
|
||||
const recursiveCommandUsed = RECURSIVE_CMDS.has(noptExploratoryResults.argv.remain[0])
|
||||
let commandName = getCommandName(noptExploratoryResults.argv.remain)
|
||||
@@ -67,6 +57,15 @@ export default async function parseCliArgs (
|
||||
cmd = opts.fallbackCommand!
|
||||
commandName = opts.fallbackCommand!
|
||||
inputArgv.unshift(opts.fallbackCommand!)
|
||||
} else if (noptExploratoryResults['help']) {
|
||||
return {
|
||||
argv: noptExploratoryResults.argv,
|
||||
cmd: 'help',
|
||||
options: {},
|
||||
params: noptExploratoryResults.argv.remain,
|
||||
unknownOptions: new Map(),
|
||||
fallbackCommandUsed: false,
|
||||
}
|
||||
}
|
||||
const types = {
|
||||
...opts.universalOptionsTypes,
|
||||
|
||||
@@ -158,6 +158,16 @@ test('if a help option is used, set cmd to "help"', async () => {
|
||||
expect(cmd).toBe('help')
|
||||
})
|
||||
|
||||
test('if a help option is used with an unknown command, do not set cmd to "help"', async () => {
|
||||
const { cmd, fallbackCommandUsed } = await parseCliArgs({
|
||||
...DEFAULT_OPTS,
|
||||
getCommandLongName: () => null,
|
||||
fallbackCommand: 'run',
|
||||
}, ['eslint', '--help'])
|
||||
expect(cmd).toBe('run')
|
||||
expect(fallbackCommandUsed).toBeTruthy()
|
||||
})
|
||||
|
||||
test('no command', async () => {
|
||||
const { cmd } = await parseCliArgs({
|
||||
...DEFAULT_OPTS,
|
||||
|
||||
Reference in New Issue
Block a user