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: Add strict mode to parser #1

Closed
wants to merge 18 commits into from
Closed

Conversation

aaronccasanova
Copy link
Owner

@aaronccasanova aaronccasanova commented Feb 19, 2022

This update builds off PR #63 and adds a strict mode option to the parser. With the restructured options API, it becomes very simple to identify unknown long options, short options, short option groups, and options with explicit values.

e.g.

// node strict.js --foo --bar
parseArgs({
  strict: true,
  options: {
    foo: { type: 'string' },
  },
});
// Error: Unknown option '--bar' is not permitted in strict mode

TODO: Assuming we decide to move forward with this implementation

  • Update PR description
  • Update the README to reflect the introduction of strict mode
  • Capture unknown and incorrect option usage (non-strict behavior)

index.js Outdated
function storeOptionValue(options, arg, value, result) {
const option = options[arg] || {};
function storeOptionValue(strict, options, arg, value, result) {
let option = options[arg];
Copy link

Choose a reason for hiding this comment

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

--toString will incorrectly be accepted as an argument with this logic. Gotta use {}.hasOwnProperty.call(options, arg) or similar.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Great callout, thanks! ef06099

@aaronccasanova aaronccasanova changed the base branch from feat/restructure-options-api to main March 3, 2022 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants