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
4d096c43
Commit
4d096c43
authored
Jan 11, 2020
by
Zachary Anderson
Committed by
Flutter GitHub Bot
Jan 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tool] Make CommandHelp context free (#48584)
parent
7dba0da2
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
332 additions
and
197 deletions
+332
-197
command_help.dart
packages/flutter_tools/lib/src/base/command_help.dart
+117
-26
resident_runner.dart
packages/flutter_tools/lib/src/resident_runner.dart
+25
-16
run_cold.dart
packages/flutter_tools/lib/src/run_cold.dart
+3
-4
run_hot.dart
packages/flutter_tools/lib/src/run_hot.dart
+5
-6
command_help_test.dart
...tter_tools/test/general.shard/base/command_help_test.dart
+163
-128
resident_runner_test.dart
...lutter_tools/test/general.shard/resident_runner_test.dart
+19
-17
No files found.
packages/flutter_tools/lib/src/base/command_help.dart
View file @
4d096c43
...
@@ -4,34 +4,125 @@
...
@@ -4,34 +4,125 @@
import
'dart:math'
as
math
;
import
'dart:math'
as
math
;
import
'../globals.dart'
as
globals
;
import
'package:meta/meta.dart'
;
import
'package:platform/platform.dart'
;
import
'logger.dart'
;
import
'terminal.dart'
;
import
'terminal.dart'
;
// ignore_for_file: non_constant_identifier_names
const
String
fire
=
'🔥'
;
const
String
fire
=
'🔥'
;
const
int
maxLineWidth
=
84
;
const
int
maxLineWidth
=
84
;
/// Encapsulates the help text construction and printing
/// Encapsulates the help text construction and printing
.
class
CommandHelp
{
class
CommandHelp
{
CommandHelp
({
@required
Logger
logger
,
@required
AnsiTerminal
terminal
,
@required
Platform
platform
,
@required
OutputPreferences
outputPreferences
,
})
:
_logger
=
logger
,
_terminal
=
terminal
,
_platform
=
platform
,
_outputPreferences
=
outputPreferences
;
final
Logger
_logger
;
final
AnsiTerminal
_terminal
;
final
Platform
_platform
;
final
OutputPreferences
_outputPreferences
;
CommandHelpOption
_L
;
CommandHelpOption
get
L
=>
_L
??=
_makeOption
(
'L'
,
'Dump layer tree to the console.'
,
'debugDumpLayerTree'
);
CommandHelpOption
_P
;
CommandHelpOption
get
P
=>
_P
??=
_makeOption
(
'P'
,
'Toggle performance overlay.'
,
'WidgetsApp.showPerformanceOverlay'
);
CommandHelpOption
_R
;
CommandHelpOption
get
R
=>
_R
??=
_makeOption
(
'R'
,
'Hot restart.'
);
CommandHelpOption
_S
;
CommandHelpOption
get
S
=>
_S
??=
_makeOption
(
'S'
,
'Dump accessibility tree in traversal order.'
,
'debugDumpSemantics'
);
CommandHelpOption
_U
;
CommandHelpOption
get
U
=>
_U
??=
_makeOption
(
'U'
,
'Dump accessibility tree in inverse hit test order.'
,
'debugDumpSemantics'
);
CommandHelpOption
_a
;
CommandHelpOption
get
a
=>
_a
??=
_makeOption
(
'a'
,
'Toggle timeline events for all widget build methods.'
,
'debugProfileWidgetBuilds'
);
CommandHelpOption
_d
;
CommandHelpOption
get
d
=>
_d
??=
_makeOption
(
'd'
,
'Detach (terminate "flutter run" but leave application running).'
);
CommandHelpOption
_h
;
CommandHelpOption
get
h
=>
_h
??=
_makeOption
(
'h'
,
'Repeat this help message.'
);
CommandHelpOption
_i
;
CommandHelpOption
get
i
=>
_i
??=
_makeOption
(
'i'
,
'Toggle widget inspector.'
,
'WidgetsApp.showWidgetInspectorOverride'
);
CommandHelpOption
_o
;
CommandHelpOption
get
o
=>
_o
??=
_makeOption
(
'o'
,
'Simulate different operating systems.'
,
'defaultTargetPlatform'
);
CommandHelpOption
_p
;
CommandHelpOption
get
p
=>
_p
??=
_makeOption
(
'p'
,
'Toggle the display of construction lines.'
,
'debugPaintSizeEnabled'
);
CommandHelpOption
_q
;
CommandHelpOption
get
q
=>
_q
??=
_makeOption
(
'q'
,
'Quit (terminate the application on the device).'
);
CommandHelpOption
_r
;
CommandHelpOption
get
r
=>
_r
??=
_makeOption
(
'r'
,
'Hot reload.
$fire$fire$fire
'
);
CommandHelpOption
_s
;
CommandHelpOption
get
s
=>
_s
??=
_makeOption
(
's'
,
'Save a screenshot to flutter.png.'
);
CommandHelpOption
_t
;
CommandHelpOption
get
t
=>
_t
??=
_makeOption
(
't'
,
'Dump rendering tree to the console.'
,
'debugDumpRenderTree'
);
CommandHelpOption
_w
;
CommandHelpOption
get
w
=>
_w
??=
_makeOption
(
'w'
,
'Dump widget hierarchy to the console.'
,
'debugDumpApp'
);
CommandHelpOption
_z
;
CommandHelpOption
get
z
=>
_z
??=
_makeOption
(
'z'
,
'Toggle elevation checker.'
);
CommandHelpOption
_makeOption
(
String
key
,
String
description
,
[
String
inParenthesis
=
''
,
])
{
return
CommandHelpOption
(
key
,
description
,
inParenthesis:
inParenthesis
,
logger:
_logger
,
terminal:
_terminal
,
platform:
_platform
,
outputPreferences:
_outputPreferences
,
);
}
}
/// Encapsulates printing help text for a single option.
class
CommandHelpOption
{
CommandHelpOption
(
this
.
key
,
this
.
description
,
{
this
.
inParenthesis
=
''
,
@required
Logger
logger
,
@required
AnsiTerminal
terminal
,
@required
Platform
platform
,
@required
OutputPreferences
outputPreferences
,
})
:
_logger
=
logger
,
_terminal
=
terminal
,
_platform
=
platform
,
_outputPreferences
=
outputPreferences
;
final
Logger
_logger
;
final
AnsiTerminal
_terminal
;
final
Platform
_platform
;
const
CommandHelp
.
_
(
this
.
key
,
this
.
description
,
[
this
.
inParenthesis
=
''
]);
final
OutputPreferences
_outputPreferences
;
static
const
CommandHelp
L
=
CommandHelp
.
_
(
'L'
,
'Dump layer tree to the console.'
,
'debugDumpLayerTree'
);
static
const
CommandHelp
P
=
CommandHelp
.
_
(
'P'
,
'Toggle performance overlay.'
,
'WidgetsApp.showPerformanceOverlay'
);
static
const
CommandHelp
R
=
CommandHelp
.
_
(
'R'
,
'Hot restart.'
);
static
const
CommandHelp
S
=
CommandHelp
.
_
(
'S'
,
'Dump accessibility tree in traversal order.'
,
'debugDumpSemantics'
);
static
const
CommandHelp
U
=
CommandHelp
.
_
(
'U'
,
'Dump accessibility tree in inverse hit test order.'
,
'debugDumpSemantics'
);
static
const
CommandHelp
a
=
CommandHelp
.
_
(
'a'
,
'Toggle timeline events for all widget build methods.'
,
'debugProfileWidgetBuilds'
);
static
const
CommandHelp
d
=
CommandHelp
.
_
(
'd'
,
'Detach (terminate "flutter run" but leave application running).'
);
static
const
CommandHelp
h
=
CommandHelp
.
_
(
'h'
,
'Repeat this help message.'
);
static
const
CommandHelp
i
=
CommandHelp
.
_
(
'i'
,
'Toggle widget inspector.'
,
'WidgetsApp.showWidgetInspectorOverride'
);
static
const
CommandHelp
o
=
CommandHelp
.
_
(
'o'
,
'Simulate different operating systems.'
,
'defaultTargetPlatform'
);
static
const
CommandHelp
p
=
CommandHelp
.
_
(
'p'
,
'Toggle the display of construction lines.'
,
'debugPaintSizeEnabled'
);
static
const
CommandHelp
q
=
CommandHelp
.
_
(
'q'
,
'Quit (terminate the application on the device).'
);
static
const
CommandHelp
r
=
CommandHelp
.
_
(
'r'
,
'Hot reload.
$fire$fire$fire
'
);
static
const
CommandHelp
s
=
CommandHelp
.
_
(
's'
,
'Save a screenshot to flutter.png.'
);
static
const
CommandHelp
t
=
CommandHelp
.
_
(
't'
,
'Dump rendering tree to the console.'
,
'debugDumpRenderTree'
);
static
const
CommandHelp
w
=
CommandHelp
.
_
(
'w'
,
'Dump widget hierarchy to the console.'
,
'debugDumpApp'
);
static
const
CommandHelp
z
=
CommandHelp
.
_
(
'z'
,
'Toggle elevation checker.'
);
/// The key associated with this command
/// The key associated with this command
final
String
key
;
final
String
key
;
...
@@ -47,12 +138,12 @@ class CommandHelp {
...
@@ -47,12 +138,12 @@ class CommandHelp {
@override
@override
String
toString
()
{
String
toString
()
{
final
StringBuffer
message
=
StringBuffer
();
final
StringBuffer
message
=
StringBuffer
();
message
.
writeAll
(<
String
>[
globals
.
terminal
.
bolden
(
key
),
description
],
' '
);
message
.
writeAll
(<
String
>[
_
terminal
.
bolden
(
key
),
description
],
' '
);
if
(
_hasTextInParenthesis
)
{
if
(
_hasTextInParenthesis
)
{
bool
wrap
=
false
;
bool
wrap
=
false
;
final
int
maxWidth
=
math
.
max
(
outputPreferences
.
wrapColumn
??
0
,
maxLineWidth
);
final
int
maxWidth
=
math
.
max
(
_
outputPreferences
.
wrapColumn
??
0
,
maxLineWidth
);
int
width
=
maxWidth
-
(
globals
.
platform
.
stdoutSupportsAnsi
?
_rawMessageLength
+
1
:
message
.
length
);
int
width
=
maxWidth
-
(
_
platform
.
stdoutSupportsAnsi
?
_rawMessageLength
+
1
:
message
.
length
);
final
String
parentheticalText
=
'(
$inParenthesis
)'
;
final
String
parentheticalText
=
'(
$inParenthesis
)'
;
if
(
width
<
parentheticalText
.
length
)
{
if
(
width
<
parentheticalText
.
length
)
{
width
=
maxWidth
;
width
=
maxWidth
;
...
@@ -65,12 +156,12 @@ class CommandHelp {
...
@@ -65,12 +156,12 @@ class CommandHelp {
// pad according to the raw text
// pad according to the raw text
message
.
write
(
''
.
padLeft
(
width
-
parentheticalText
.
length
));
message
.
write
(
''
.
padLeft
(
width
-
parentheticalText
.
length
));
message
.
write
(
globals
.
terminal
.
color
(
parentheticalText
,
TerminalColor
.
grey
));
message
.
write
(
_
terminal
.
color
(
parentheticalText
,
TerminalColor
.
grey
));
}
}
return
message
.
toString
();
return
message
.
toString
();
}
}
void
print
()
{
void
print
()
{
globals
.
printStatus
(
toString
());
_logger
.
printStatus
(
toString
());
}
}
}
}
packages/flutter_tools/lib/src/resident_runner.dart
View file @
4d096c43
...
@@ -15,6 +15,7 @@ import 'base/file_system.dart';
...
@@ -15,6 +15,7 @@ import 'base/file_system.dart';
import
'base/io.dart'
as
io
;
import
'base/io.dart'
as
io
;
import
'base/logger.dart'
;
import
'base/logger.dart'
;
import
'base/signals.dart'
;
import
'base/signals.dart'
;
import
'base/terminal.dart'
show
outputPreferences
;
import
'base/utils.dart'
;
import
'base/utils.dart'
;
import
'build_info.dart'
;
import
'build_info.dart'
;
import
'codegen.dart'
;
import
'codegen.dart'
;
...
@@ -607,7 +608,13 @@ abstract class ResidentRunner {
...
@@ -607,7 +608,13 @@ abstract class ResidentRunner {
artifactDirectory
=
dillOutputPath
==
null
artifactDirectory
=
dillOutputPath
==
null
?
globals
.
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_tool.'
)
?
globals
.
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_tool.'
)
:
globals
.
fs
.
file
(
dillOutputPath
).
parent
,
:
globals
.
fs
.
file
(
dillOutputPath
).
parent
,
assetBundle
=
AssetBundleFactory
.
instance
.
createBundle
()
{
assetBundle
=
AssetBundleFactory
.
instance
.
createBundle
(),
commandHelp
=
CommandHelp
(
logger:
globals
.
logger
,
terminal:
globals
.
terminal
,
platform:
globals
.
platform
,
outputPreferences:
outputPreferences
,
)
{
if
(!
artifactDirectory
.
existsSync
())
{
if
(!
artifactDirectory
.
existsSync
())
{
artifactDirectory
.
createSync
(
recursive:
true
);
artifactDirectory
.
createSync
(
recursive:
true
);
}
}
...
@@ -640,6 +647,8 @@ abstract class ResidentRunner {
...
@@ -640,6 +647,8 @@ abstract class ResidentRunner {
final
String
mainPath
;
final
String
mainPath
;
final
AssetBundle
assetBundle
;
final
AssetBundle
assetBundle
;
final
CommandHelp
commandHelp
;
bool
_exited
=
false
;
bool
_exited
=
false
;
Completer
<
int
>
_finished
=
Completer
<
int
>();
Completer
<
int
>
_finished
=
Completer
<
int
>();
bool
hotMode
;
bool
hotMode
;
...
@@ -1005,29 +1014,29 @@ abstract class ResidentRunner {
...
@@ -1005,29 +1014,29 @@ abstract class ResidentRunner {
void
printHelpDetails
()
{
void
printHelpDetails
()
{
if
(
flutterDevices
.
any
((
FlutterDevice
d
)
=>
d
.
device
.
supportsScreenshot
))
{
if
(
flutterDevices
.
any
((
FlutterDevice
d
)
=>
d
.
device
.
supportsScreenshot
))
{
C
ommandHelp
.
s
.
print
();
c
ommandHelp
.
s
.
print
();
}
}
if
(
supportsServiceProtocol
)
{
if
(
supportsServiceProtocol
)
{
C
ommandHelp
.
w
.
print
();
c
ommandHelp
.
w
.
print
();
C
ommandHelp
.
t
.
print
();
c
ommandHelp
.
t
.
print
();
if
(
isRunningDebug
)
{
if
(
isRunningDebug
)
{
C
ommandHelp
.
L
.
print
();
c
ommandHelp
.
L
.
print
();
C
ommandHelp
.
S
.
print
();
c
ommandHelp
.
S
.
print
();
C
ommandHelp
.
U
.
print
();
c
ommandHelp
.
U
.
print
();
C
ommandHelp
.
i
.
print
();
c
ommandHelp
.
i
.
print
();
C
ommandHelp
.
p
.
print
();
c
ommandHelp
.
p
.
print
();
C
ommandHelp
.
o
.
print
();
c
ommandHelp
.
o
.
print
();
C
ommandHelp
.
z
.
print
();
c
ommandHelp
.
z
.
print
();
}
else
{
}
else
{
C
ommandHelp
.
S
.
print
();
c
ommandHelp
.
S
.
print
();
C
ommandHelp
.
U
.
print
();
c
ommandHelp
.
U
.
print
();
}
}
// `P` should precede `a`
// `P` should precede `a`
C
ommandHelp
.
P
.
print
();
c
ommandHelp
.
P
.
print
();
C
ommandHelp
.
a
.
print
();
c
ommandHelp
.
a
.
print
();
}
}
if
(
flutterDevices
.
any
((
FlutterDevice
d
)
=>
d
.
device
.
supportsScreenshot
))
{
if
(
flutterDevices
.
any
((
FlutterDevice
d
)
=>
d
.
device
.
supportsScreenshot
))
{
C
ommandHelp
.
s
.
print
();
c
ommandHelp
.
s
.
print
();
}
}
}
}
...
...
packages/flutter_tools/lib/src/run_cold.dart
View file @
4d096c43
...
@@ -6,7 +6,6 @@ import 'dart:async';
...
@@ -6,7 +6,6 @@ import 'dart:async';
import
'package:meta/meta.dart'
;
import
'package:meta/meta.dart'
;
import
'base/command_help.dart'
;
import
'base/file_system.dart'
;
import
'base/file_system.dart'
;
import
'device.dart'
;
import
'device.dart'
;
import
'globals.dart'
as
globals
;
import
'globals.dart'
as
globals
;
...
@@ -186,11 +185,11 @@ class ColdRunner extends ResidentRunner {
...
@@ -186,11 +185,11 @@ class ColdRunner extends ResidentRunner {
printHelpDetails
();
printHelpDetails
();
}
}
}
}
C
ommandHelp
.
h
.
print
();
c
ommandHelp
.
h
.
print
();
if
(
_didAttach
)
{
if
(
_didAttach
)
{
C
ommandHelp
.
d
.
print
();
c
ommandHelp
.
d
.
print
();
}
}
C
ommandHelp
.
q
.
print
();
c
ommandHelp
.
q
.
print
();
for
(
final
FlutterDevice
device
in
flutterDevices
)
{
for
(
final
FlutterDevice
device
in
flutterDevices
)
{
final
String
dname
=
device
.
device
.
name
;
final
String
dname
=
device
.
device
.
name
;
if
(
device
.
vmService
!=
null
)
{
if
(
device
.
vmService
!=
null
)
{
...
...
packages/flutter_tools/lib/src/run_hot.dart
View file @
4d096c43
...
@@ -11,7 +11,6 @@ import 'package:meta/meta.dart';
...
@@ -11,7 +11,6 @@ import 'package:meta/meta.dart';
import
'package:pool/pool.dart'
;
import
'package:pool/pool.dart'
;
import
'base/async_guard.dart'
;
import
'base/async_guard.dart'
;
import
'base/command_help.dart'
;
import
'base/context.dart'
;
import
'base/context.dart'
;
import
'base/file_system.dart'
;
import
'base/file_system.dart'
;
import
'base/logger.dart'
;
import
'base/logger.dart'
;
...
@@ -1046,15 +1045,15 @@ class HotRunner extends ResidentRunner {
...
@@ -1046,15 +1045,15 @@ class HotRunner extends ResidentRunner {
@override
@override
void
printHelp
({
@required
bool
details
})
{
void
printHelp
({
@required
bool
details
})
{
globals
.
printStatus
(
'Flutter run key commands.'
);
globals
.
printStatus
(
'Flutter run key commands.'
);
C
ommandHelp
.
r
.
print
();
c
ommandHelp
.
r
.
print
();
if
(
canHotRestart
)
{
if
(
canHotRestart
)
{
C
ommandHelp
.
R
.
print
();
c
ommandHelp
.
R
.
print
();
}
}
C
ommandHelp
.
h
.
print
();
c
ommandHelp
.
h
.
print
();
if
(
_didAttach
)
{
if
(
_didAttach
)
{
C
ommandHelp
.
d
.
print
();
c
ommandHelp
.
d
.
print
();
}
}
C
ommandHelp
.
q
.
print
();
c
ommandHelp
.
q
.
print
();
if
(
details
)
{
if
(
details
)
{
printHelpDetails
();
printHelpDetails
();
}
}
...
...
packages/flutter_tools/test/general.shard/base/command_help_test.dart
View file @
4d096c43
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/resident_runner_test.dart
View file @
4d096c43
...
@@ -364,6 +364,8 @@ void main() {
...
@@ -364,6 +364,8 @@ void main() {
residentRunner
.
printHelp
(
details:
true
);
residentRunner
.
printHelp
(
details:
true
);
final
CommandHelp
commandHelp
=
residentRunner
.
commandHelp
;
// supports service protocol
// supports service protocol
expect
(
residentRunner
.
supportsServiceProtocol
,
true
);
expect
(
residentRunner
.
supportsServiceProtocol
,
true
);
// isRunningDebug
// isRunningDebug
...
@@ -372,23 +374,23 @@ void main() {
...
@@ -372,23 +374,23 @@ void main() {
expect
(
testLogger
.
statusText
,
equals
(
expect
(
testLogger
.
statusText
,
equals
(
<
dynamic
>[
<
dynamic
>[
'Flutter run key commands.'
,
'Flutter run key commands.'
,
C
ommandHelp
.
r
,
c
ommandHelp
.
r
,
C
ommandHelp
.
R
,
c
ommandHelp
.
R
,
C
ommandHelp
.
h
,
c
ommandHelp
.
h
,
C
ommandHelp
.
q
,
c
ommandHelp
.
q
,
C
ommandHelp
.
s
,
c
ommandHelp
.
s
,
C
ommandHelp
.
w
,
c
ommandHelp
.
w
,
C
ommandHelp
.
t
,
c
ommandHelp
.
t
,
C
ommandHelp
.
L
,
c
ommandHelp
.
L
,
C
ommandHelp
.
S
,
c
ommandHelp
.
S
,
C
ommandHelp
.
U
,
c
ommandHelp
.
U
,
C
ommandHelp
.
i
,
c
ommandHelp
.
i
,
C
ommandHelp
.
p
,
c
ommandHelp
.
p
,
C
ommandHelp
.
o
,
c
ommandHelp
.
o
,
C
ommandHelp
.
z
,
c
ommandHelp
.
z
,
C
ommandHelp
.
P
,
c
ommandHelp
.
P
,
C
ommandHelp
.
a
,
c
ommandHelp
.
a
,
C
ommandHelp
.
s
,
c
ommandHelp
.
s
,
'An Observatory debugger and profiler on null is available at: null'
,
'An Observatory debugger and profiler on null is available at: null'
,
''
''
].
join
(
'
\n
'
)
].
join
(
'
\n
'
)
...
...
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