[flutter_tools] Provide global options with subcommand help text (#54884)

This commit is contained in:
Zachary Anderson
2020-04-17 08:54:48 -07:00
committed by GitHub
parent 6c70a8fef6
commit bec63a54bf
2 changed files with 24 additions and 2 deletions

View File

@@ -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`.

View File

@@ -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';