Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
b02f68a6
Unverified
Commit
b02f68a6
authored
Aug 05, 2022
by
Aman Verma
Committed by
GitHub
Aug 05, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] refactor stringsArg (#105032)
parent
fe7b6de4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletion
+33
-1
flutter_command.dart
packages/flutter_tools/lib/src/runner/flutter_command.dart
+3
-1
args_test.dart
packages/flutter_tools/test/general.shard/args_test.dart
+30
-0
No files found.
packages/flutter_tools/lib/src/runner/flutter_command.dart
View file @
b02f68a6
...
...
@@ -1556,7 +1556,9 @@ abstract class FlutterCommand extends Command<void> {
int
?
intArg
(
String
name
)
=>
argResults
?[
name
]
as
int
?;
/// Gets the parsed command-line option named [name] as `List<String>`.
List
<
String
>
stringsArg
(
String
name
)
=>
argResults
?[
name
]
as
List
<
String
>?
??
<
String
>[];
List
<
String
>
stringsArg
(
String
name
)
{
return
argResults
![
name
]!
as
List
<
String
>?
??
<
String
>[];
}
}
/// A mixin which applies an implementation of [requiredArtifacts] that only
...
...
packages/flutter_tools/test/general.shard/args_test.dart
View file @
b02f68a6
...
...
@@ -72,6 +72,36 @@ void main() {
expect
(
command
.
stringArgDeprecated
(
'key'
),
'value'
);
expect
(()
=>
command
.
stringArgDeprecated
(
'empty'
),
throwsA
(
const
TypeMatcher
<
ArgumentError
>()));
});
testUsingContext
(
'List<String> safe argResults'
,
()
async
{
final
DummyFlutterCommand
command
=
DummyFlutterCommand
(
commandFunction:
()
async
{
return
const
FlutterCommandResult
(
ExitStatus
.
success
);
}
);
final
FlutterCommandRunner
runner
=
FlutterCommandRunner
(
verboseHelp:
true
);
command
.
argParser
.
addMultiOption
(
'key'
,
allowed:
<
String
>[
'a'
,
'b'
,
'c'
],
);
// argResults will be null at this point, if attempt to read them is made,
// exception `Null check operator used on a null value` would be thrown.
expect
(()
=>
command
.
stringsArg
(
'key'
),
throwsA
(
const
TypeMatcher
<
TypeError
>()));
runner
.
addCommand
(
command
);
await
runner
.
run
(<
String
>[
'dummy'
,
'--key'
,
'a'
]);
// throws error when trying to parse non-existent key.
expect
(()
=>
command
.
stringsArg
(
'empty'
),
throwsA
(
const
TypeMatcher
<
ArgumentError
>()));
expect
(
command
.
stringsArg
(
'key'
),
<
String
>[
'a'
]);
await
runner
.
run
(<
String
>[
'dummy'
,
'--key'
,
'a'
,
'--key'
,
'b'
]);
expect
(
command
.
stringsArg
(
'key'
),
<
String
>[
'a'
,
'b'
]);
await
runner
.
run
(<
String
>[
'dummy'
]);
expect
(
command
.
stringsArg
(
'key'
),
<
String
>[]);
});
}
void
verifyCommandRunner
(
CommandRunner
<
Object
>
runner
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment