-
Notifications
You must be signed in to change notification settings - Fork 40
CPLAT-16476 Allow args after separator to TestTool #364
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
Conversation
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
|
||
final args = argResults.arguments; | ||
final rest = argResults.rest; | ||
var rCursor = 0; |
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.
Maybe a clearer name? e.g. argSeparatorPosition
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 a little torn on this. I originally had something like what you suggested, but then usages like this feel a bit more confusing:
if (args[aCursor] == rest[separatorArgPosition]) {
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.
Yeah, I see that. What about not abbreviating. argsCursor and restCursor. I see aCursor at a glance and read it as "an instance of Cursor". Or argsIndex and restIndex?
final rest = argResults.rest; | ||
var rCursor = 0; | ||
for (var aCursor = 0; aCursor < args.length; aCursor++) { | ||
// Iterate through the original args until we hit the first separator. |
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 having trouble following this. It seems like the only result of this is setting rCursor. But isn't rCursor just args.indexOf('--')
?
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.
That would be the position of the separator within the original arguments list, which isn't necessarily the same as the position at which the separator should be restored in the rest
arguments list, since the latter excludes flags and options that were parsed by the ArgParser. So for example:
final argParser = ArgParser()
..addOption('output')
..addFlag('verbose');
final argResults = argParser.parse(['foo', '--output', 'out', '--verbose', '--', 'bar', '--baz']);
print(argResults.arguments);
// ['foo', '--output', 'out', '--verbose', '--', 'bar', '--baz']
// In this list, separator index is 4
print(argResults.rest);
// ['foo', 'bar', '--baz']
// In this list, we want to restore the separator at index 1
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, I get it. Ugh. It'd be better if ArgParser just didn't think it knew about '--' and included it.
183b8b4
final rest = argResults.rest; | ||
var rCursor = 0; | ||
for (var aCursor = 0; aCursor < args.length; aCursor++) { | ||
// Iterate through the original args until we hit the first separator. |
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, I get it. Ugh. It'd be better if ArgParser just didn't think it knew about '--' and included it.
|
||
final args = argResults.arguments; | ||
final rest = argResults.rest; | ||
var rCursor = 0; |
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.
Yeah, I see that. What about not abbreviating. argsCursor and restCursor. I see aCursor at a glance and read it as "an instance of Cursor". Or argsIndex and restIndex?
QA +1
|
@Workiva/release-management-p |
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.
+1 from RM
TestTool
to allow arguments after a separator (--
). These arguments will always be passed to thedart test
process. The main use case for this is integration with IDE plugins that enable running tests directly from the IDE.FunctionTool
to allow arguments after a separator (--
). There isn't a strong reason to disallow this since the function tool could do anything it wants with those args (and now we have a concrete use case for just that).takeAllArgs
(the arg mapper util used withCompoundTool
) so that it now properly restores the first separator (--
) if present in the original arguments list.