Skip to content

[Fix] ensure --help is intercepted on any command #2277

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

Merged
merged 1 commit into from
Aug 9, 2020

Conversation

naomiquinones
Copy link
Contributor

This fixes #911

Issue: Prevent flags from being parsed if the help flag is present in the list of arguments to nvm

Even if nvm doesn't support the --help flag on individual tasks it would be more user friendly to prevent any action being carried out if the --help flag is present

What we did: Check arguments list for help flag and display help then exit without parsing other flags

Test added: nvm_check_for_help

Co-authored-by: Naomi Quinones <[email protected]>
Co-authored-by: Dena Burd <[email protected]>
nvm.sh Outdated
for i in ${argsList[@]}
do
case $i in
'help'|'-help'|'--help')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit surprised to see nvm -help as an alias for nvm --help (i'd totally forgotten about nvm help). Why the extra alias? (typically, single-dash arguments are always only one letter; only double-dash arguments are longer words)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case someone were to type one dash either because they are not too familiar with nvm/shell or because it's a typo, then this would catch this variation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb the extra -help is now -h and the test adjusted for it.

@ljharb ljharb added the feature requests I want a new feature in nvm! label Aug 6, 2020
@ljharb
Copy link
Member

ljharb commented Aug 6, 2020

a few tests are failing.

@ljharb ljharb changed the title Check for help [Fix] ensure --help is intercepted on any command Aug 9, 2020
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks great.

@ljharb ljharb merged commit 1bf567b into nvm-sh:master Aug 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature requests I want a new feature in nvm!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't act when --help flag specified
3 participants