[flutter_tools] Provide global options with subcommand help text (#54884)
This commit is contained in:
@@ -848,6 +848,23 @@ abstract class FlutterCommand extends Command<void> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String get usage {
|
||||
final String usageWithoutDescription = super.usage.substring(
|
||||
// The description plus two newlines.
|
||||
description.length + 2,
|
||||
);
|
||||
final String help = <String>[
|
||||
description,
|
||||
'',
|
||||
'Global options:',
|
||||
runner.argParser.usage,
|
||||
'',
|
||||
usageWithoutDescription,
|
||||
].join('\n');
|
||||
return help;
|
||||
}
|
||||
|
||||
ApplicationPackageStore applicationPackages;
|
||||
|
||||
/// Gets the parsed command-line option named [name] as `bool`.
|
||||
|
||||
@@ -42,6 +42,12 @@ void main() {
|
||||
when(mockProcessInfo.maxRss).thenReturn(10);
|
||||
});
|
||||
|
||||
testUsingContext('help text contains global options', () {
|
||||
final FakeCommand fake = FakeCommand();
|
||||
createTestCommandRunner(fake);
|
||||
expect(fake.usage, contains('Global options:\n'));
|
||||
});
|
||||
|
||||
testUsingContext('honors shouldUpdateCache false', () async {
|
||||
final DummyFlutterCommand flutterCommand = DummyFlutterCommand(shouldUpdateCache: false);
|
||||
await flutterCommand.run();
|
||||
@@ -423,10 +429,9 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
class FakeCommand extends FlutterCommand {
|
||||
@override
|
||||
String get description => null;
|
||||
String get description => 'A fake command';
|
||||
|
||||
@override
|
||||
String get name => 'fake';
|
||||
|
||||
Reference in New Issue
Block a user