Unverified Commit 36cf1158 authored by Devon Carew's avatar Devon Carew Committed by GitHub

add the full path to a flutter command (#16720)

* add the full path to a flutter command

* remove an unused import

* review comments
parent 90ca8152
......@@ -190,13 +190,11 @@ class RunCommand extends RunCommandBase {
@override
Future<String> get usagePath async {
final String command = shouldUseHotMode() ? 'hotrun' : name;
final String command = await super.usagePath;
if (devices == null)
return command;
// Return 'run/ios'.
if (devices.length > 1)
else if (devices.length > 1)
return '$command/all';
else
return '$command/${getNameForTargetPlatform(await devices[0].targetPlatform)}';
......
......@@ -243,7 +243,16 @@ abstract class FlutterCommand extends Command<Null> {
/// The path to send to Google Analytics. Return null here to disable
/// tracking of the command.
Future<String> get usagePath async => name;
Future<String> get usagePath async {
if (parent is FlutterCommand) {
final FlutterCommand commandParent = parent;
final String path = await commandParent.usagePath;
// Don't report for parents that return null for usagePath.
return path == null ? null : '$path/$name';
} else {
return name;
}
}
/// Additional usage values to be sent with the usage ping.
Future<Map<String, String>> get usageValues async => const <String, String>{};
......@@ -274,6 +283,8 @@ abstract class FlutterCommand extends Command<Null> {
} finally {
final DateTime endTime = clock.now();
printTrace('"flutter $name" took ${getElapsedAsMilliseconds(endTime.difference(startTime))}.');
// Note that this is checking the result of the call to 'usagePath'
// (a Future<String>), and not the result of evaluating the Future.
if (usagePath != null) {
final List<String> labels = <String>[];
if (commandResult?.exitStatus != null)
......
......@@ -5,9 +5,11 @@
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build.dart';
import 'package:flutter_tools/src/commands/config.dart';
import 'package:flutter_tools/src/commands/doctor.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/usage.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart';
......@@ -131,6 +133,21 @@ void main() {
Doctor: () => mockDoctor,
Usage: () => mockUsage,
});
testUsingContext('single command usage path', () async {
final FlutterCommand doctorCommand = new DoctorCommand();
expect(await doctorCommand.usagePath, 'doctor');
}, overrides: <Type, Generator>{
Usage: () => mockUsage,
});
testUsingContext('compound command usage path', () async {
final BuildCommand buildCommand = new BuildCommand();
final FlutterCommand buildApkCommand = buildCommand.subcommands['apk'];
expect(await buildApkCommand.usagePath, 'build/apk');
}, overrides: <Type, Generator>{
Usage: () => mockUsage,
});
});
group('analytics bots', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment