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
8fbf89b9
Unverified
Commit
8fbf89b9
authored
May 17, 2022
by
Aman Verma
Committed by
GitHub
May 17, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] throw error when argResults is null (#103827)
parent
9651f1d7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
19 deletions
+17
-19
flutter_command.dart
packages/flutter_tools/lib/src/runner/flutter_command.dart
+4
-4
args_test.dart
packages/flutter_tools/test/general.shard/args_test.dart
+13
-15
No files found.
packages/flutter_tools/lib/src/runner/flutter_command.dart
View file @
8fbf89b9
...
...
@@ -1524,20 +1524,20 @@ abstract class FlutterCommand extends Command<void> {
/// Gets the parsed command-line option named [name] as a `bool?`.
bool
?
boolArg
(
String
name
)
{
if
(
argResults
==
null
||
!
argParser
.
options
.
containsKey
(
name
))
{
if
(!
argParser
.
options
.
containsKey
(
name
))
{
return
null
;
}
return
argResults
?[
name
]
as
bool
?
;
return
argResults
![
name
]
as
bool
;
}
/// Gets the parsed command-line option named [name] as a `String`.
String
?
stringArgDeprecated
(
String
name
)
=>
argResults
?[
name
]
as
String
?;
String
?
stringArg
(
String
name
)
{
if
(
argResults
==
null
||
!
argParser
.
options
.
containsKey
(
name
))
{
if
(!
argParser
.
options
.
containsKey
(
name
))
{
return
null
;
}
return
argResults
?[
name
]
as
String
?
;
return
argResults
![
name
]
as
String
;
}
/// Gets the parsed command-line option named [name] as an `int`.
...
...
packages/flutter_tools/test/general.shard/args_test.dart
View file @
8fbf89b9
...
...
@@ -15,19 +15,6 @@ import '../src/context.dart';
import
'../src/testbed.dart'
;
import
'runner/utils.dart'
;
class
CommandDummy
extends
FlutterCommand
{
@override
String
get
description
=>
'description'
;
@override
String
get
name
=>
'test'
;
@override
Future
<
FlutterCommandResult
>
runCommand
()
async
{
return
FlutterCommandResult
.
success
();
}
}
void
main
(
)
{
test
(
'Help for command line arguments is consistently styled and complete'
,
()
=>
Testbed
().
run
(()
{
final
FlutterCommandRunner
runner
=
FlutterCommandRunner
(
verboseHelp:
true
);
...
...
@@ -47,6 +34,9 @@ void main() {
final
FlutterCommandRunner
runner
=
FlutterCommandRunner
(
verboseHelp:
true
);
command
.
argParser
.
addFlag
(
'key'
);
command
.
argParser
.
addFlag
(
'key-false'
);
// 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
.
boolArg
(
'key'
),
throwsA
(
const
TypeMatcher
<
TypeError
>()));
runner
.
addCommand
(
command
);
await
runner
.
run
(<
String
>[
'dummy'
,
'--key'
]);
...
...
@@ -62,11 +52,19 @@ void main() {
});
testUsingContext
(
'String? safe argResults'
,
()
async
{
final
CommandDummy
command
=
CommandDummy
();
final
DummyFlutterCommand
command
=
DummyFlutterCommand
(
commandFunction:
()
async
{
return
const
FlutterCommandResult
(
ExitStatus
.
success
);
}
);
final
FlutterCommandRunner
runner
=
FlutterCommandRunner
(
verboseHelp:
true
);
command
.
argParser
.
addOption
(
'key'
);
// 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
.
stringArg
(
'key'
),
throwsA
(
const
TypeMatcher
<
TypeError
>()));
runner
.
addCommand
(
command
);
await
runner
.
run
(<
String
>[
'
test
'
,
'--key=value'
]);
await
runner
.
run
(<
String
>[
'
dummy
'
,
'--key=value'
]);
expect
(
command
.
stringArg
(
'key'
),
'value'
);
expect
(
command
.
stringArg
(
'empty'
),
null
);
...
...
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