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

[ts-command-line] Update to argparse@2.0.1 and default allow_abbrev to false #4403

Closed
wants to merge 6 commits into from

Conversation

D4N14L
Copy link
Member

@D4N14L D4N14L commented Oct 21, 2023

Summary

This PR bumps the version of argparse consumed to 2.0.1. It also defaults allow_abbrev to false when creating the underlying argument parser, to avoid issues with unexplicit parameter usage (ex. --debug matching --debug-heft-reporter which comes from the @rushstack/heft-jest-plugin package). More documentation on the parameter can be found here: https://docs.python.org/3/library/argparse.html#allow-abbrev

Details

API usage across the entire argparse surface had to be updated, since the underlying library now uses snake_casing, but behaviour remains the same.

How it was tested

All unit tests passed for ts-command-line, new test added for abbreviation scenario and confirmed the test failed without setting allow_abbrev to false.

Impacted documentation

None. This was undocumented and unintended behaviour.

@D4N14L D4N14L changed the title User/danade/update argparse [ts-command-line] Update to argparse@2.0.1 and default allow_abbrev to false Oct 21, 2023

if (parameter.undocumentedSynonyms?.length) {
argumentGroup.addArgument(parameter.undocumentedSynonyms, {
for (const undocumentedSynonym of parameter.undocumentedSynonyms || []) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrapping in the if is marginally more efficient


a longer description

Optional arguments:
-h, --help Show this help message and exit.
optional arguments:
Copy link
Contributor

Choose a reason for hiding this comment

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

This inconsistent formatting looks bad; if the base is changing should we change to match?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think so. Beginning sentences with a lower case letter looks objectively worse. I checked a few other popular CLI tools (tsc, eslint, PowerShell, gcc) and their --help always uses proper English capitalization. Doing so also encourages grammatically complete sentences, which may inspire better documentation. Notably python --help does show unprofessional lowercase capitalization, however Python's own pip --help uses caps like all the other examples.

I believe this behavior is customizable by implementing our own argparse help formatter.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The API allows us to suppress the default --help parameter and define it ourselves.

I created an issue nodeca/argparse#175 requesting a more general solution, however the NPM package hasn't been updated in 3 years, so we'll see if they reply. 😄

@D4N14L D4N14L closed this Oct 23, 2023
@D4N14L
Copy link
Member Author

D4N14L commented Oct 23, 2023

Closed in favor of #4405 which implements the main goal of this PR, without wholesale disabling allow_abbrev or needing to bump argparse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

None yet

3 participants