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

feat: introduces strictCommands() subset of strict mode #1540

Merged
merged 5 commits into from Feb 18, 2020
Merged

Conversation

bcoe
Copy link
Member

@bcoe bcoe commented Feb 9, 2020

I have met your demands @boneskull

This seemed like a reasonable feature request, and I'm excited to see whether you get use out of it.

Code review appreciated.


BREAKING CHANGE: if you use .demandCommand() or .demandCommand(1), in conjunction
with defining commands, .strictCommands() is enabled automatically.

Since the breaking changes to yargs-parser were for undocumented behavior (and 15.x.x was actually a regression with regards to the parsing of booleans, I'm going to try to release 15.x.x as a non-breaking change; if the candidate release seems to be breaking too many folks, we can revisit this decision).

BREAKING CHANGE: if you use `.demandCommand()` or `.demandCommand(1)`, in conjunction
with defining commands, `.strictCommands()` is enabled automatically.

if (unknown.length > 0) {
usage.fail(__n(
'Unknown argument: %s',
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be "Unknown command"? The error as written looks too similar to the "unknown argument" output.

Copy link
Member Author

Choose a reason for hiding this comment

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

you are 100% correct ... the reason I was thinking of using Unknown argument: was to avoid having to update all the languages yargs has been translated into, alternatively we could introduce the new phrase and let folks gradually submit translations.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's more important to be precise with error messages, even if it adds another untranslated string.

Copy link
Member

Choose a reason for hiding this comment

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

For fr.json, this would be:

  "Unknown command: %s": {
    "one": "Commande inconnue : %s",
    "other": "Commandes inconnues : %s"
  },

The space before ":" is intentional, as we do have a space in French before every punctuation sign drawn in more than one piece (":", "?", "!", ";", etc. but not ","). I see I will have some cleanup to do in fr.json

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 @mleguen mind making a PR for the french translation in a separate PR, as I know we've been fixing a few issues with translations recently.

Copy link
Member

Choose a reason for hiding this comment

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

@bcoe No problem. I will do it when I will rebase the PR for french translations, once this one is merged.

lib/validation.js Outdated Show resolved Hide resolved
Copy link
Member

@mleguen mleguen left a comment

Choose a reason for hiding this comment

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

Thanks @bcoe. Mind adding some tests with command aliases?


if (unknown.length > 0) {
usage.fail(__n(
'Unknown argument: %s',
Copy link
Member

Choose a reason for hiding this comment

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

For fr.json, this would be:

  "Unknown command: %s": {
    "one": "Commande inconnue : %s",
    "other": "Commandes inconnues : %s"
  },

The space before ":" is intentional, as we do have a space in French before every punctuation sign drawn in more than one piece (":", "?", "!", ";", etc. but not ","). I see I will have some cleanup to do in fr.json

test/validation.js Show resolved Hide resolved
Copy link
Contributor

@boneskull boneskull left a comment

Choose a reason for hiding this comment

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

for doing my bidding, I express to you gratitude

@bcoe
Copy link
Member Author

bcoe commented Feb 13, 2020

@boneskull @mleguen I think I'm going to hold off on the breaking change until the next major, based on conversations we had in the tooling chat.

@bcoe bcoe changed the title feat!: introduces strictCommands() subset of strict mode feat: introduces strictCommands() subset of strict mode Feb 16, 2020
@bcoe bcoe merged commit 1d4cca3 into master Feb 18, 2020
@bcoe bcoe deleted the boneskull-demands branch February 18, 2020 20:47
@bcoe
Copy link
Member Author

bcoe commented Mar 8, 2020

@boneskull when you have a moment try npm i yargs@next it has the strict command functionality you requested.

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

Successfully merging this pull request may close these issues.

None yet

5 participants