Skip to content

feat: respect required/optional option values - #1328

Merged
grabbou merged 2 commits into
masterfrom
feat/validate-options
Nov 26, 2020
Merged

grabbou merged 2 commits into
masterfrom
feat/validate-options

Conversation

@grabbou

@grabbou grabbou commented Nov 26, 2020 •

Copy link
Copy Markdown
Member

Summary:

Historically, we used to have assertRequiredOptions function present in the codebase as a workaround for a broken Commander feature.

1/ It is now not needed to have it. While testing this PR, it turned out this function was necessary as Commander correctly throws on missing values. It was either a mistake while doing the original PR or the underlying issue got fixed.

2/ We don't need any additional logic to enforce values for options, e.g. --path <value>. All we have to do is to use <> instead of []. I have corrected the declaration when necessary to avoid issues.

Originally started by @jamesgeorge007

Test Plan:

Run react-native start --port and see it throw an error of a missing port value.

{
name: '--port [number]',
default: process.env.RCT_METRO_PORT || 8081,
parse: (val: number) => String(val),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is incorrect. Values to be parsed are always string.

name: '--all [boolean]',
name: '--all',
description: 'Link all native modules and assets',
parse: (val: string) => val.toLowerCase().split(','),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not sure about this one, we don't support comma separated values, nor --all true, so just sticking to --all.

@jamesgeorge007 jamesgeorge007 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CI is failing since you have removed assertRequiredOptions(); but not the reference to it.

import assertRequiredOptions from './tools/assertRequiredOptions';

@grabbou

grabbou commented Nov 26, 2020

Copy link
Copy Markdown
Member Author

Good catch!

@thymikee thymikee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, let's do it. I added @jamesgeorge007 to the description so he gets some attribution.

@jamesgeorge007

Copy link
Copy Markdown
Contributor

#1324 (comment) Isn't this an issue?

@grabbou

grabbou commented Nov 26, 2020

Copy link
Copy Markdown
Member Author

It will not.

So here's what happened.

I thought that assertRequiredOptions was required because of Commander bug and it was a workaround. Turns out, it was unnecessary because when an option value was missing (after setting <name> instead of [name]), it was Commander that was throwing a bug.

So they must have fixed it in the meantime and we never refactored this code out.

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