Commit 48915069 authored by Devon Carew's avatar Devon Carew Committed by GitHub

add a --machine mode to flutter config (#11112)

* add a --machine mode to flutter config

* review feedback
parent 40a65e1f
......@@ -68,7 +68,7 @@ Future<Null> main(List<String> args) async {
new AnalyzeCommand(verboseHelp: verboseHelp),
new BuildCommand(verboseHelp: verboseHelp),
new ChannelCommand(),
new ConfigCommand(),
new ConfigCommand(verboseHelp: verboseHelp),
new CreateCommand(),
new DaemonCommand(hidden: !verboseHelp),
new DevicesCommand(),
......
......@@ -128,7 +128,9 @@ class AndroidStudio implements Comparable<AndroidStudio> {
.listSync()
.where((FileSystemEntity e) => e is Directory);
for (Directory directory in directories) {
if (directory.basename == 'Android Studio.app') {
final String name = directory.basename;
// An exact match, or something like 'Android Studio 3.0 Preview.app'.
if (name.startsWith('Android Studio') && name.endsWith('.app')) {
candidatePaths.add(directory);
} else if (!directory.path.endsWith('.app')) {
_checkForStudio(directory.path);
......
......@@ -23,7 +23,7 @@ class AnalyzeCommand extends FlutterCommand {
argParser.addOption('dart-sdk', valueHelp: 'path-to-sdk', help: 'The path to the Dart SDK.', hide: !verboseHelp);
// Hidden option to enable a benchmarking mode.
argParser.addFlag('benchmark', negatable: false, hide: !verboseHelp, help: 'Also output the analysis time');
argParser.addFlag('benchmark', negatable: false, hide: !verboseHelp, help: 'Also output the analysis time.');
usesPubOption();
......
......@@ -3,23 +3,27 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import '../android/android_studio.dart';
import '../globals.dart';
import '../runner/flutter_command.dart';
import '../usage.dart';
class ConfigCommand extends FlutterCommand {
ConfigCommand() {
ConfigCommand({ bool verboseHelp: false }) {
argParser.addFlag('analytics',
negatable: true,
help: 'Enable or disable reporting anonymously tool usage statistics and crash reports.');
argParser.addFlag(
'clear-ios-signing-cert',
argParser.addFlag('clear-ios-signing-cert',
negatable: false,
help: 'Clear the saved development certificate choice used to sign apps for iOS device deployment'
);
help: 'Clear the saved development certificate choice used to sign apps for iOS device deployment.');
argParser.addOption('gradle-dir', help: 'The gradle install directory.');
argParser.addOption('android-studio-dir', help: 'The Android Studio install directory.');
argParser.addFlag('machine',
negatable: false,
hide: !verboseHelp,
help: 'Pring config values as json.');
}
@override
......@@ -53,6 +57,9 @@ class ConfigCommand extends FlutterCommand {
@override
Future<Null> runCommand() async {
if (argResults['machine'])
return handleMachine();
if (argResults.wasParsed('analytics')) {
final bool value = argResults['analytics'];
flutterUsage.enabled = value;
......@@ -72,6 +79,21 @@ class ConfigCommand extends FlutterCommand {
printStatus(usage);
}
Future<Null> handleMachine() async {
// Get all the current values.
final Map<String, dynamic> results = <String, dynamic>{};
for (String key in config.keys) {
results[key] = config.getValue(key);
}
// Ensure we send any calculated ones, if overrides don't exist.
if (results['android-studio-dir'] == null && androidStudio != null) {
results['android-studio-dir'] = androidStudio.directory;
}
printStatus(JSON.encode(results));
}
void _updateConfig(String keyName, String keyValue) {
if (keyValue.isEmpty) {
config.removeValue(keyName);
......
......@@ -2,17 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';
import 'package:flutter_tools/src/android/android_studio.dart';
import 'package:flutter_tools/src/base/config.dart';
import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/commands/config.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import 'src/context.dart';
void main() {
Config config;
MockAndroidStudio mockAndroidStudio;
setUp(() {
final Directory tempDiretory = fs.systemTempDirectory.createTempSync('flutter_test');
final File file = fs.file(fs.path.join(tempDiretory.path, '.settings'));
final Directory tempDirectory = fs.systemTempDirectory.createTempSync('flutter_test');
final File file = fs.file(fs.path.join(tempDirectory.path, '.settings'));
config = new Config(file);
mockAndroidStudio = new MockAndroidStudio();
});
group('config', () {
......@@ -32,5 +43,24 @@ void main() {
expect(config.getValue('foo'), null);
expect(config.keys, isNot(contains('foo')));
});
testUsingContext('machine flag', () async {
final BufferLogger logger = context[Logger];
final ConfigCommand command = new ConfigCommand();
await command.handleMachine();
expect(logger.statusText, isNotEmpty);
final dynamic json = JSON.decode(logger.statusText);
expect(json, isMap);
expect(json.containsKey('android-studio-dir'), true);
expect(json['android-studio-dir'], isNotNull);
}, overrides: <Type, Generator>{
AndroidStudio: () => mockAndroidStudio,
});
});
}
class MockAndroidStudio extends Mock implements AndroidStudio, Comparable<AndroidStudio> {
@override
String get directory => 'path/to/android/stdio';
}
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