Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
cli: accept csv for array values #8933
cli: accept csv for array values #8933
Changes from 5 commits
6b8c607
9fe961a
35e2f01
879b288
3e3cc4c
ee44360
0d1a611
0067f00
6f58b90
e4da3a9
d49db90
2402ce8
2b46961
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this ends up somewhat confusing from the caller's perspective since it's no longer explicitly optional (even though we usually call it with no args) and when we do pass an argument it's still a single string (it's annoying that the
yargs
types require this becauseyargs
definitely supports parsing just a string).What about keeping it
string=
and doingconst y = manualArgv ? yargs([manualArgv]) : yargs;
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused on how it's confusing to the caller?
if reverting the change, would you want the code using multiple args (admittedly it's just test code) to look like this?
or this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes from me. Maybe it's just that I haven't been completely indoctrinated to rest parameters yet, but to me an optional
manualArgv?: string
parameter is a lot clearer than...manaulArgv: string[]
at informing that the argument is optional. It's not a huge deal since it's not a commonly used interface, but it's only test code that uses this, so it makes sense to me to make the real use case clear in the signature.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha, actually, that test failure may be because our version of yargs doesn't take an array at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It passes locally.
(EDIT: misread the build log. one sec)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok the issue is that if you pass in an array, you cannot have each item have multiple args. test just needs to change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also I guess they expect some preprocessing, b/c
=
is required too. 6f58b90There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can only omit the
=
when passing in as a single string? This seems like the real downside...we should be able to write tests using both styles since the real deal accepts bothThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't buy us much except having to coerce with
/** @type {string[]} */
belowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would like to keep
/** @type {string[]} */
otherwise more errors come up. I added a comment saying why we can assume it to be a string[].LH.CliFlags
one could be removed if you want.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it's wrong because all of this is wrong :)
The ts-ignore was suppressing a different error than it said (I assume/hope it changed at some point), but the comment was still correct ('
yargs()
is incorrectly typed as not returning itself'): all the calls on yargs afterhelp()
are of typeany
and returnany
. In addition:LH.CliFlags[keyof LH.CliFlags]
is definitely not a string array, really it should beLH.CliFlags['onlyAudits'|'onlyCategories'|'output'|'plugins'|'skipAudits']
string[]
because yargs is returning that for the subset of keys we care about, assigning back asstring[]
is still not correct even for that subset because e.g.output
isLH.OutputMode[]
, notstring[]
(and that's ignoring trying to reassign back toLH.CliFlags[keyof LH.CliFlags]
). This will be an error in tsc 3.5+.I think the most honest thing is to just leave as
any
internal togetFlags
with a note about why and leave it up to tests to verify thatgetFlags
really is returningLH.CliFlags
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're settling on
Array<keyof LH.CliFlags>
for complex types that aren't juststring[]
or w/e, though if you ask @brendankenny we're always settling onArray<*>
;)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, yes, because it's an array, not a string, so why would you put that information last? :P They could have gone
[string]
, but they used that up on tuplesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once we figure out other feedback would love the
--window-size
andblockedUrlPattern
counter examples here too :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blockedUrlPattern
just b/c comma could be in a pattern? what if we could escape it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm lets not do that :)