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

fix: Do not treat an array of config values as a sub-command config section #1221

Merged
merged 6 commits into from
Jan 23, 2018

Conversation

rpl
Copy link
Member

@rpl rpl commented Jan 19, 2018

This PR contains a set of proposed changes to fix #1213, #1214 and #1215

#1213 is fixed by prevent applyConfigToArgv to recurse on an array of config values (by consider it as a sub-command config section by mistake)

#1214 is fixed by checking if adjustedArgv.verbose is true after we loaded and applied the config file and then calling logStream.makeVerbose accordingly.

#1215 proposed fix is (as describe in this comment) to mark explicitly as array the options that may makes sense as an array of values in the config file

@rpl rpl requested a review from kumar303 January 19, 2018 19:26
@coveralls
Copy link

coveralls commented Jan 19, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 5fa17c8 on rpl:fix/config-loading-issues-1213-1215 into 47ce662 on mozilla:master.

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

I like the idea of switching these options to array -- simple and effective 👍

Is there a way to tell yargs not to allow multiple declarations of the other arguments (like --artifacts-dir)? All I see is nargs(1) but I don't think that's what we want.

I had some change requests around Flow types and some test cleanup.

pref: ['pref1=true', 'pref2=false'],
};

// TODO: expect a raised exception array is not a string
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this todo comment mean? Was there another test you wanted to add?

globalOpt: {
pref: {
demand: false,
type: 'string',
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 type: 'array' so that it tests the bug you were fixing more directly? I'm a bit confused because the exception message in your assertion doesn't seem to match the spec of this test.

@@ -401,7 +401,7 @@ Example: $0 --help run.
'run against multiple targets.',
default: 'firefox-desktop',
demand: false,
type: 'string',
type: 'array',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also update the Flow type:

https://github.com/rpl/web-ext/blob/3848c777b290b4c5ed6ad1af0436afe5f952b005/src/cmd/run.js#L44

It should now just be target?: Array<string>.

Copy link
Member Author

Choose a reason for hiding this comment

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

I applied these changes to the flow types in
025db7c

@@ -447,15 +447,15 @@ Example: $0 --help run.
'preference.',
demand: false,
requiresArg: true,
type: 'string',
type: 'array',
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also update this Flow type:

https://github.com/rpl/web-ext/blob/3848c777b290b4c5ed6ad1af0436afe5f952b005/src/firefox/preferences.js#L120

It should now just be cliPrefs: Array<string>. I think you may need to update some tests after that.

coerce: coerceCLICustomPreference,
},
'start-url': {
alias: ['u', 'url'],
describe: 'Launch firefox at specified page',
demand: false,
requiresArg: true,
type: 'string',
type: 'array',
Copy link
Contributor

Choose a reason for hiding this comment

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

@rpl
Copy link
Member Author

rpl commented Jan 23, 2018

@kumar303 This should be ready for another review, besides applying the changes suggested in the previous review, I've also introduced a fix (and a new test case) for #1214 in
6ded415

@rpl rpl requested a review from kumar303 January 23, 2018 12:04
Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

Looks good! I suggested some cleanup but nothing mandatory.

src/program.js Outdated
logStream.makeVerbose();

if (!versionLogged) {
log.info('Version:', getVersion(absolutePackageDir));
Copy link
Contributor

Choose a reason for hiding this comment

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

Oof. This duplication is unfortunate. I can't think of another way to do it though. I suppose you could pull it into a shared function just for a bit more maintainability.

Copy link
Member Author

@rpl rpl Jan 23, 2018

Choose a reason for hiding this comment

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

yeah, I agree, I've refactored the part that enables the verbose mode and prints the version into a class method and then reused it into the two places where we have to be sure that the verbose mode is being enabled (when it is specified on the command line and when it is only specified in a config file).

Let me know how it looks to you.

const loadJSConfigFile = makeConfigLoader({
configObjects: {
[customConfig]: {
sourceDir: finalSourceDir,
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem like it's necessary for the test. You could remove it along with the variable.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 removed

@kumar303
Copy link
Contributor

Let's ship it

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.

Crash when pref option is an array in config file
3 participants