Refactor all the commands to be Commands from the Args package. Also use CommandRunner for the top-level command.
This commit is contained in:
parent
a49120c667
commit
cae053c353
@ -2,17 +2,126 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:sky_tools/src/application_package.dart';
|
||||
import 'package:sky_tools/src/build.dart';
|
||||
import 'package:sky_tools/src/cache.dart';
|
||||
import 'package:sky_tools/src/common.dart';
|
||||
import 'package:sky_tools/src/init.dart';
|
||||
import 'package:sky_tools/src/install.dart';
|
||||
import 'package:sky_tools/src/run_mojo.dart';
|
||||
import 'package:sky_tools/src/application_package.dart';
|
||||
|
||||
class FlutterCommandRunner extends CommandRunner {
|
||||
FlutterCommandRunner() : super('flutter', 'Manage your flutter app development.') {
|
||||
argParser.addFlag('verbose',
|
||||
abbr: 'v',
|
||||
negatable: false,
|
||||
help: 'Noisy logging, including all shell commands executed.');
|
||||
argParser.addFlag('very-verbose',
|
||||
negatable: false,
|
||||
help: 'Very noisy logging, including the output of all '
|
||||
'shell commands executed.');
|
||||
|
||||
argParser.addSeparator('Global build selection options:');
|
||||
argParser.addFlag('debug',
|
||||
negatable: false,
|
||||
help:
|
||||
'Set this if you are building Sky locally and want to use the debug build products. '
|
||||
'When set, attempts to automaticaly determine sky-src-path if sky-src-path is '
|
||||
'not set. Not normally required.');
|
||||
argParser.addFlag('release',
|
||||
negatable: false,
|
||||
help:
|
||||
'Set this if you are building Sky locally and want to use the release build products. '
|
||||
'When set, attempts to automaticaly determine sky-src-path if sky-src-path is '
|
||||
'not set. Note that release is not compatible with the listen command '
|
||||
'on iOS devices and simulators. Not normally required.');
|
||||
argParser.addOption('sky-src-path',
|
||||
help: 'Path to your Sky src directory, if you are building Sky locally. '
|
||||
'Ignored if neither debug nor release is set. Not normally required.');
|
||||
argParser.addOption('android-debug-build-path',
|
||||
help:
|
||||
'Path to your Android Debug out directory, if you are building Sky locally. '
|
||||
'This path is relative to sky-src-path. Not normally required.',
|
||||
defaultsTo: 'out/android_Debug/');
|
||||
argParser.addOption('android-release-build-path',
|
||||
help:
|
||||
'Path to your Android Release out directory, if you are building Sky locally. '
|
||||
'This path is relative to sky-src-path. Not normally required.',
|
||||
defaultsTo: 'out/android_Release/');
|
||||
argParser.addOption('ios-debug-build-path',
|
||||
help:
|
||||
'Path to your iOS Debug out directory, if you are building Sky locally. '
|
||||
'This path is relative to sky-src-path. Not normally required.',
|
||||
defaultsTo: 'out/ios_Debug/');
|
||||
argParser.addOption('ios-release-build-path',
|
||||
help:
|
||||
'Path to your iOS Release out directory, if you are building Sky locally. '
|
||||
'This path is relative to sky-src-path. Not normally required.',
|
||||
defaultsTo: 'out/ios_Release/');
|
||||
argParser.addOption('ios-sim-debug-build-path',
|
||||
help:
|
||||
'Path to your iOS Simulator Debug out directory, if you are building Sky locally. '
|
||||
'This path is relative to sky-src-path. Not normally required.',
|
||||
defaultsTo: 'out/ios_sim_Debug/');
|
||||
argParser.addOption('ios-sim-release-build-path',
|
||||
help:
|
||||
'Path to your iOS Simulator Release out directory, if you are building Sky locally. '
|
||||
'This path is relative to sky-src-path. Not normally required.',
|
||||
defaultsTo: 'out/ios_sim_Release/');
|
||||
}
|
||||
|
||||
Future<int> runCommand(ArgResults topLevelResults) async {
|
||||
if (topLevelResults['verbose']) {
|
||||
Logger.root.level = Level.INFO;
|
||||
}
|
||||
|
||||
if (topLevelResults['very-verbose']) {
|
||||
Logger.root.level = Level.FINE;
|
||||
}
|
||||
|
||||
_setupPaths(topLevelResults);
|
||||
|
||||
return super.runCommand(topLevelResults);
|
||||
}
|
||||
|
||||
void _setupPaths(ArgResults results) {
|
||||
if (results['debug'] || results['release']) {
|
||||
if (results['sky-src-path'] == null) {
|
||||
// TODO(iansf): Figure out how to get the default src path
|
||||
assert(false);
|
||||
}
|
||||
ApplicationPackageFactory.srcPath = results['sky-src-path'];
|
||||
} else {
|
||||
assert(false);
|
||||
// TODO(iansf): set paths up for commands using PREBUILT binaries
|
||||
// ApplicationPackageFactory.setBuildPath(BuildType.PREBUILT,
|
||||
// BuildPlatform.android, results['android-debug-build-path']);
|
||||
}
|
||||
|
||||
if (results['debug']) {
|
||||
ApplicationPackageFactory.defaultBuildType = BuildType.debug;
|
||||
ApplicationPackageFactory.setBuildPath(BuildType.debug,
|
||||
BuildPlatform.android, results['android-debug-build-path']);
|
||||
ApplicationPackageFactory.setBuildPath(
|
||||
BuildType.debug, BuildPlatform.iOS, results['ios-debug-build-path']);
|
||||
ApplicationPackageFactory.setBuildPath(BuildType.debug,
|
||||
BuildPlatform.iOSSimulator, results['ios-sim-debug-build-path']);
|
||||
}
|
||||
if (results['release']) {
|
||||
ApplicationPackageFactory.defaultBuildType = BuildType.release;
|
||||
ApplicationPackageFactory.setBuildPath(BuildType.release,
|
||||
BuildPlatform.android, results['android-release-build-path']);
|
||||
ApplicationPackageFactory.setBuildPath(BuildType.release, BuildPlatform.iOS,
|
||||
results['ios-release-build-path']);
|
||||
ApplicationPackageFactory.setBuildPath(BuildType.release,
|
||||
BuildPlatform.iOSSimulator, results['ios-sim-release-build-path']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main(List<String> args) {
|
||||
Logger.root.level = Level.WARNING;
|
||||
@ -26,161 +135,11 @@ void main(List<String> args) {
|
||||
}
|
||||
});
|
||||
|
||||
Map<String, CommandHandler> handlers = {};
|
||||
|
||||
ArgParser parser = new ArgParser();
|
||||
parser.addSeparator('basic options:');
|
||||
parser.addFlag('help',
|
||||
abbr: 'h', negatable: false, help: 'Display this help message.');
|
||||
parser.addFlag('verbose',
|
||||
abbr: 'v',
|
||||
negatable: false,
|
||||
help: 'Noisy logging, including all shell commands executed.');
|
||||
parser.addFlag('very-verbose',
|
||||
negatable: false,
|
||||
help: 'Very noisy logging, including the output of all '
|
||||
'shell commands executed.');
|
||||
|
||||
parser.addSeparator('build selection options:');
|
||||
parser.addFlag('debug',
|
||||
negatable: false,
|
||||
help:
|
||||
'Set this if you are building Sky locally and want to use the debug build products. '
|
||||
'When set, attempts to automaticaly determine sky-src-path if sky-src-path is '
|
||||
'not set. Not normally required.');
|
||||
parser.addFlag('release',
|
||||
negatable: false,
|
||||
help:
|
||||
'Set this if you are building Sky locally and want to use the release build products. '
|
||||
'When set, attempts to automaticaly determine sky-src-path if sky-src-path is '
|
||||
'not set. Note that release is not compatible with the listen command '
|
||||
'on iOS devices and simulators. Not normally required.');
|
||||
parser.addOption('sky-src-path',
|
||||
help: 'Path to your Sky src directory, if you are building Sky locally. '
|
||||
'Ignored if neither debug nor release is set. Not normally required.');
|
||||
parser.addOption('android-debug-build-path',
|
||||
help:
|
||||
'Path to your Android Debug out directory, if you are building Sky locally. '
|
||||
'This path is relative to sky-src-path. Not normally required.',
|
||||
defaultsTo: 'out/android_Debug/');
|
||||
parser.addOption('android-release-build-path',
|
||||
help:
|
||||
'Path to your Android Release out directory, if you are building Sky locally. '
|
||||
'This path is relative to sky-src-path. Not normally required.',
|
||||
defaultsTo: 'out/android_Release/');
|
||||
parser.addOption('ios-debug-build-path',
|
||||
help:
|
||||
'Path to your iOS Debug out directory, if you are building Sky locally. '
|
||||
'This path is relative to sky-src-path. Not normally required.',
|
||||
defaultsTo: 'out/ios_Debug/');
|
||||
parser.addOption('ios-release-build-path',
|
||||
help:
|
||||
'Path to your iOS Release out directory, if you are building Sky locally. '
|
||||
'This path is relative to sky-src-path. Not normally required.',
|
||||
defaultsTo: 'out/ios_Release/');
|
||||
parser.addOption('ios-sim-debug-build-path',
|
||||
help:
|
||||
'Path to your iOS Simulator Debug out directory, if you are building Sky locally. '
|
||||
'This path is relative to sky-src-path. Not normally required.',
|
||||
defaultsTo: 'out/ios_sim_Debug/');
|
||||
parser.addOption('ios-sim-release-build-path',
|
||||
help:
|
||||
'Path to your iOS Simulator Release out directory, if you are building Sky locally. '
|
||||
'This path is relative to sky-src-path. Not normally required.',
|
||||
defaultsTo: 'out/ios_sim_Release/');
|
||||
|
||||
parser.addSeparator('commands:');
|
||||
|
||||
for (CommandHandler handler in [
|
||||
new BuildCommandHandler(),
|
||||
new CacheCommandHandler(),
|
||||
new InitCommandHandler(),
|
||||
new InstallCommandHandler(),
|
||||
new RunMojoCommandHandler(),
|
||||
]) {
|
||||
parser.addCommand(handler.name, handler.parser);
|
||||
handlers[handler.name] = handler;
|
||||
}
|
||||
|
||||
ArgResults results;
|
||||
|
||||
try {
|
||||
results = parser.parse(args);
|
||||
} catch (e) {
|
||||
_printUsage(parser, handlers, e is FormatException ? e.message : '${e}');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (results['verbose']) {
|
||||
Logger.root.level = Level.INFO;
|
||||
}
|
||||
|
||||
if (results['very-verbose']) {
|
||||
Logger.root.level = Level.FINE;
|
||||
}
|
||||
|
||||
_setupPaths(results);
|
||||
|
||||
if (results['help']) {
|
||||
_printUsage(parser, handlers);
|
||||
} else if (results.command != null) {
|
||||
handlers[results.command.name]
|
||||
.processArgResults(results.command)
|
||||
.then((int code) => exit(code))
|
||||
.catchError((e, stack) {
|
||||
print('Error running ' + results.command.name + ': $e');
|
||||
print(stack);
|
||||
exit(2);
|
||||
});
|
||||
} else {
|
||||
_printUsage(parser, handlers, 'No command specified.');
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void _setupPaths(ArgResults results) {
|
||||
if (results['debug'] || results['release']) {
|
||||
if (results['sky-src-path'] == null) {
|
||||
// TODO(iansf): Figure out how to get the default src path
|
||||
assert(false);
|
||||
}
|
||||
ApplicationPackageFactory.srcPath = results['sky-src-path'];
|
||||
} else {
|
||||
assert(false);
|
||||
// TODO(iansf): set paths up for commands using PREBUILT binaries
|
||||
// ApplicationPackageFactory.setBuildPath(BuildType.PREBUILT,
|
||||
// BuildPlatform.android, results['android-debug-build-path']);
|
||||
}
|
||||
|
||||
if (results['debug']) {
|
||||
ApplicationPackageFactory.defaultBuildType = BuildType.debug;
|
||||
ApplicationPackageFactory.setBuildPath(BuildType.debug,
|
||||
BuildPlatform.android, results['android-debug-build-path']);
|
||||
ApplicationPackageFactory.setBuildPath(
|
||||
BuildType.debug, BuildPlatform.iOS, results['ios-debug-build-path']);
|
||||
ApplicationPackageFactory.setBuildPath(BuildType.debug,
|
||||
BuildPlatform.iOSSimulator, results['ios-sim-debug-build-path']);
|
||||
}
|
||||
if (results['release']) {
|
||||
ApplicationPackageFactory.defaultBuildType = BuildType.release;
|
||||
ApplicationPackageFactory.setBuildPath(BuildType.release,
|
||||
BuildPlatform.android, results['android-release-build-path']);
|
||||
ApplicationPackageFactory.setBuildPath(BuildType.release, BuildPlatform.iOS,
|
||||
results['ios-release-build-path']);
|
||||
ApplicationPackageFactory.setBuildPath(BuildType.release,
|
||||
BuildPlatform.iOSSimulator, results['ios-sim-release-build-path']);
|
||||
}
|
||||
}
|
||||
|
||||
void _printUsage(ArgParser parser, Map<String, CommandHandler> handlers,
|
||||
[String message]) {
|
||||
if (message != null) {
|
||||
print('${message}\n');
|
||||
}
|
||||
print('usage: sky_tools <command> [arguments]');
|
||||
print('');
|
||||
print(parser.usage);
|
||||
handlers.forEach((String command, CommandHandler handler) {
|
||||
print(' ${command.padRight(10)} ${handler.description}');
|
||||
});
|
||||
new FlutterCommandRunner()
|
||||
..addCommand(new BuildCommand())
|
||||
..addCommand(new CacheCommand())
|
||||
..addCommand(new InitCommand())
|
||||
..addCommand(new InstallCommand())
|
||||
..addCommand(new RunMojoCommand())
|
||||
..run(args);
|
||||
}
|
||||
|
@ -8,11 +8,10 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:archive/archive.dart';
|
||||
import 'package:args/args.dart';
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
import 'artifacts.dart';
|
||||
import 'common.dart';
|
||||
|
||||
const String _kSnapshotKey = 'snapshot_blob.bin';
|
||||
const List<String> _kDensities = const ['drawable-xxhdpi'];
|
||||
@ -127,41 +126,33 @@ Future<ArchiveFile> _createSnapshotFile(String snapshotPath) async {
|
||||
return new ArchiveFile(_kSnapshotKey, content.length, content);
|
||||
}
|
||||
|
||||
class BuildCommandHandler extends CommandHandler {
|
||||
BuildCommandHandler() : super('build', 'Create a Flutter app.');
|
||||
|
||||
ArgParser get parser {
|
||||
ArgParser parser = new ArgParser();
|
||||
parser.addFlag('help', abbr: 'h', negatable: false);
|
||||
parser.addOption('asset-base', defaultsTo: 'packages/material_design_icons/icons');
|
||||
parser.addOption('compiler');
|
||||
parser.addOption('main', defaultsTo: 'lib/main.dart');
|
||||
parser.addOption('manifest');
|
||||
parser.addOption('output-file', abbr: 'o', defaultsTo: 'app.flx');
|
||||
parser.addOption('package-root', defaultsTo: 'packages');
|
||||
parser.addOption('snapshot', defaultsTo: 'snapshot_blob.bin');
|
||||
return parser;
|
||||
class BuildCommand extends Command {
|
||||
final name = 'build';
|
||||
final description = 'Create a Flutter app.';
|
||||
BuildCommand() {
|
||||
argParser.addOption('asset-base', defaultsTo: 'packages/material_design_icons/icons');
|
||||
argParser.addOption('compiler');
|
||||
argParser.addOption('main', defaultsTo: 'lib/main.dart');
|
||||
argParser.addOption('manifest');
|
||||
argParser.addOption('output-file', abbr: 'o', defaultsTo: 'app.flx');
|
||||
argParser.addOption('package-root', defaultsTo: 'packages');
|
||||
argParser.addOption('snapshot', defaultsTo: 'snapshot_blob.bin');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> processArgResults(ArgResults results) async {
|
||||
if (results['help']) {
|
||||
print(parser.usage);
|
||||
return 0;
|
||||
}
|
||||
|
||||
String manifestPath = results['manifest'];
|
||||
Future<int> run() async {
|
||||
String manifestPath = argResults['manifest'];
|
||||
Map manifestDescriptor = await _loadManifest(manifestPath);
|
||||
Iterable<_Asset> assets = _parseAssets(manifestDescriptor, manifestPath);
|
||||
Iterable<_MaterialAsset> materialAssets = _parseMaterialAssets(manifestDescriptor);
|
||||
|
||||
Archive archive = new Archive();
|
||||
|
||||
String snapshotPath = results['snapshot'];
|
||||
String snapshotPath = argResults['snapshot'];
|
||||
await _compileSnapshot(
|
||||
compilerPath: results['compiler'],
|
||||
mainPath: results['main'],
|
||||
packageRoot: results['package-root'],
|
||||
compilerPath: argResults['compiler'],
|
||||
mainPath: argResults['main'],
|
||||
packageRoot: argResults['package-root'],
|
||||
snapshotPath: snapshotPath);
|
||||
archive.addFile(await _createSnapshotFile(snapshotPath));
|
||||
|
||||
@ -169,12 +160,12 @@ class BuildCommandHandler extends CommandHandler {
|
||||
archive.addFile(await _createFile(asset.key, asset.base));
|
||||
|
||||
for (_MaterialAsset asset in materialAssets) {
|
||||
ArchiveFile file = await _createFile(asset.key, results['asset-base']);
|
||||
ArchiveFile file = await _createFile(asset.key, argResults['asset-base']);
|
||||
if (file != null)
|
||||
archive.addFile(file);
|
||||
}
|
||||
|
||||
File outputFile = new File(results['output-file']);
|
||||
File outputFile = new File(argResults['output-file']);
|
||||
await outputFile.writeAsString('#!mojo mojo:sky_viewer\n');
|
||||
await outputFile.writeAsBytes(new ZipEncoder().encode(archive), mode: FileMode.APPEND);
|
||||
return 0;
|
||||
|
@ -6,63 +6,48 @@ library sky_tools.cache;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import 'artifacts.dart';
|
||||
import 'common.dart';
|
||||
|
||||
final Logger _logging = new Logger('sky_tools.cache');
|
||||
|
||||
class CacheCommandHandler extends CommandHandler {
|
||||
CacheCommandHandler() : super('cache', 'Manages sky_tools\' cache of binary artifacts.');
|
||||
|
||||
ArgParser get parser {
|
||||
ArgParser parser = new ArgParser();
|
||||
parser.addFlag('help', abbr: 'h', negatable: false);
|
||||
parser.addOption('package-root', defaultsTo: 'packages');
|
||||
ArgParser clearParser = parser.addCommand('clear');
|
||||
clearParser.addFlag('help', abbr: 'h', negatable: false);
|
||||
ArgParser populateParser = parser.addCommand('populate');
|
||||
populateParser.addFlag('help', abbr: 'h', negatable: false);
|
||||
return parser;
|
||||
class CacheCommand extends Command {
|
||||
final name = 'cache';
|
||||
final description = 'Manages sky_tools\' cache of binary artifacts.';
|
||||
CacheCommand() {
|
||||
addSubcommand(new _ClearCommand());
|
||||
addSubcommand(new _PopulateCommand());
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> _clear(String packageRoot, ArgResults results) async {
|
||||
if (results['help']) {
|
||||
print('Clears all artifacts from the cache.');
|
||||
print(parser.usage);
|
||||
return 0;
|
||||
}
|
||||
ArtifactStore artifacts = new ArtifactStore(packageRoot);
|
||||
await artifacts.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Future<int> _populate(String packageRoot, ArgResults results) async {
|
||||
if (results['help']) {
|
||||
print('Populates the cache with all known artifacts.');
|
||||
print(parser.usage);
|
||||
return 0;
|
||||
}
|
||||
ArtifactStore artifacts = new ArtifactStore(packageRoot);
|
||||
await artifacts.populate();
|
||||
return 0;
|
||||
class _ClearCommand extends Command {
|
||||
final name = 'clear';
|
||||
final description = 'Clears all artifacts from the cache.';
|
||||
_ClearCommand() {
|
||||
argParser.addOption('package-root', defaultsTo: 'packages');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> processArgResults(ArgResults results) async {
|
||||
if (results['help'] || results.command == null) {
|
||||
print(parser.usage);
|
||||
return 0;
|
||||
}
|
||||
if (results.command.name == 'clear') {
|
||||
return _clear(results['package-root'], results.command);
|
||||
} else if (results.command.name == 'populate') {
|
||||
return _populate(results['package-root'], results.command);
|
||||
} else {
|
||||
_logging.severe('Unknown cache command \"${results.command.name}\"');
|
||||
return 2;
|
||||
}
|
||||
Future<int> run() async {
|
||||
ArtifactStore artifacts = new ArtifactStore(argResults['package-root']);
|
||||
await artifacts.populate();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class _PopulateCommand extends Command {
|
||||
final name = 'populate';
|
||||
final description = 'Populates the cache with all known artifacts.';
|
||||
_PopulateCommand() {
|
||||
argParser.addOption('package-root', defaultsTo: 'packages');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> run() async {
|
||||
ArtifactStore artifacts = new ArtifactStore(argResults['package-root']);
|
||||
await artifacts.populate();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
|
||||
abstract class CommandHandler {
|
||||
final String name;
|
||||
final String description;
|
||||
|
||||
CommandHandler(this.name, this.description);
|
||||
|
||||
ArgParser get parser;
|
||||
|
||||
/// Returns 0 for no errors or warnings executing command, 1 for warnings, 2
|
||||
/// for errors.
|
||||
Future<int> processArgResults(ArgResults results);
|
||||
|
||||
void printUsage([String message]) {
|
||||
if (message != null) {
|
||||
print('${message}\n');
|
||||
}
|
||||
print('usage: sky_tools ${name} [arguments]');
|
||||
print('');
|
||||
print(parser.usage);
|
||||
}
|
||||
|
||||
String toString() => name;
|
||||
}
|
@ -9,8 +9,8 @@ import 'dart:io';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'process_wrapper.dart';
|
||||
import 'application_package.dart';
|
||||
import 'process_wrapper.dart';
|
||||
|
||||
final Logger _logging = new Logger('sky_tools.device');
|
||||
|
||||
|
@ -7,41 +7,30 @@ library sky_tools.init;
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:mustache4dart/mustache4dart.dart' as mustache;
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
import 'common.dart';
|
||||
|
||||
class InitCommandHandler extends CommandHandler {
|
||||
InitCommandHandler() : super('init', 'Create a new sky project.');
|
||||
|
||||
ArgParser get parser {
|
||||
// TODO: Add a --template option for template selection when we have more than one.
|
||||
ArgParser parser = new ArgParser();
|
||||
parser.addFlag('help',
|
||||
abbr: 'h', negatable: false, help: 'Display this help message.');
|
||||
parser.addOption('out', abbr: 'o', help: 'The output directory.');
|
||||
parser.addFlag('pub',
|
||||
class InitCommand extends Command {
|
||||
final name = 'init';
|
||||
final description = 'Create a new sky project.';
|
||||
InitCommand() {
|
||||
argParser.addOption('out', abbr: 'o', help: 'The output directory.');
|
||||
argParser.addFlag('pub',
|
||||
defaultsTo: true,
|
||||
help: 'Whether to run pub after the project has been created.');
|
||||
return parser;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> processArgResults(ArgResults results) async {
|
||||
if (results['help']) {
|
||||
printUsage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!results.wasParsed('out')) {
|
||||
printUsage('No option specified for the output directory.');
|
||||
Future<int> run() async {
|
||||
if (!argResults.wasParsed('out')) {
|
||||
print('No option specified for the output directory.');
|
||||
print(argParser.getUsage());
|
||||
return 2;
|
||||
}
|
||||
|
||||
// TODO: Confirm overwrite of an existing directory with the user.
|
||||
Directory out = new Directory(results['out']);
|
||||
Directory out = new Directory(argResults['out']);
|
||||
|
||||
new SkySimpleTemplate().generateInto(out);
|
||||
|
||||
@ -58,7 +47,7 @@ Or if the Sky APK is not already on your device, run:
|
||||
|
||||
''';
|
||||
|
||||
if (results['pub']) {
|
||||
if (argResults['pub']) {
|
||||
print("Running pub get...");
|
||||
Process process =
|
||||
await Process.start('pub', ['get'], workingDirectory: out.path);
|
||||
|
@ -6,32 +6,19 @@ library sky_tools.install;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:args/command_runner.dart';
|
||||
|
||||
import 'application_package.dart';
|
||||
import 'common.dart';
|
||||
import 'device.dart';
|
||||
|
||||
class InstallCommandHandler extends CommandHandler {
|
||||
class InstallCommand extends Command {
|
||||
final name = 'install';
|
||||
final description = 'Install your Flutter app on attached devices.';
|
||||
AndroidDevice android = null;
|
||||
InstallCommandHandler([this.android])
|
||||
: super('install', 'Install your Sky app on attached devices.');
|
||||
InstallCommand([this.android]);
|
||||
|
||||
@override
|
||||
ArgParser get parser {
|
||||
ArgParser parser = new ArgParser();
|
||||
parser.addFlag('help',
|
||||
abbr: 'h', negatable: false, help: 'Display this help message.');
|
||||
return parser;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> processArgResults(ArgResults results) async {
|
||||
if (results['help']) {
|
||||
printUsage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Future<int> run() async {
|
||||
bool installedSomewhere = false;
|
||||
|
||||
Map<BuildPlatform, ApplicationPackage> packages =
|
||||
|
@ -8,26 +8,23 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'artifacts.dart';
|
||||
import 'common.dart';
|
||||
import 'process.dart';
|
||||
|
||||
final Logger _logging = new Logger('sky_tools.run_mojo');
|
||||
|
||||
class RunMojoCommandHandler extends CommandHandler {
|
||||
RunMojoCommandHandler() : super('run_mojo', 'Run a Flutter app in mojo.');
|
||||
|
||||
ArgParser get parser {
|
||||
ArgParser parser = new ArgParser();
|
||||
parser.addFlag('android', negatable: false, help: 'Run on an Android device');
|
||||
parser.addFlag('help', abbr: 'h', negatable: false);
|
||||
parser.addOption('app', defaultsTo: 'app.flx');
|
||||
parser.addOption('mojo-path', help: 'Path to directory containing mojo_shell and services');
|
||||
parser.addOption('package-root', defaultsTo: 'packages');
|
||||
return parser;
|
||||
class RunMojoCommand extends Command {
|
||||
final name = 'run_mojo';
|
||||
final description = 'Run a Flutter app in mojo.';
|
||||
RunMojoCommand() {
|
||||
argParser.addFlag('android', negatable: false, help: 'Run on an Android device');
|
||||
argParser.addOption('app', defaultsTo: 'app.flx');
|
||||
argParser.addOption('mojo-path', help: 'Path to directory containing mojo_shell and services');
|
||||
argParser.addOption('package-root', defaultsTo: 'packages');
|
||||
}
|
||||
|
||||
Future<String> _makePathAbsolute(String relativePath) async {
|
||||
@ -71,22 +68,18 @@ class RunMojoCommandHandler extends CommandHandler {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> processArgResults(ArgResults results) async {
|
||||
if (results['help']) {
|
||||
print(parser.usage);
|
||||
return 0;
|
||||
}
|
||||
if (results['mojo-path'] == null) {
|
||||
Future<int> run() async {
|
||||
if (argResults['mojo-path'] == null) {
|
||||
_logging.severe('Must specify --mojo-path to mojo_run');
|
||||
return 1;
|
||||
}
|
||||
String packageRoot = results['package-root'];
|
||||
String packageRoot = argResults['package-root'];
|
||||
ArtifactStore artifacts = new ArtifactStore(packageRoot);
|
||||
String appPath = await _makePathAbsolute(results['app']);
|
||||
if (results['android']) {
|
||||
return _runAndroid(results, appPath, artifacts);
|
||||
String appPath = await _makePathAbsolute(argResults['app']);
|
||||
if (argResults['android']) {
|
||||
return _runAndroid(argResults, appPath, artifacts);
|
||||
} else {
|
||||
return _runLinux(results, appPath, artifacts);
|
||||
return _runLinux(argResults, appPath, artifacts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,11 @@
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:sky_tools/src/init.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'src/common.dart';
|
||||
|
||||
main() => defineTests();
|
||||
|
||||
defineTests() {
|
||||
@ -27,14 +25,13 @@ defineTests() {
|
||||
|
||||
// Verify that we create a project that is well-formed.
|
||||
test('init sky-simple', () async {
|
||||
InitCommandHandler handler = new InitCommandHandler();
|
||||
MockArgResults results = new MockArgResults();
|
||||
when(results['help']).thenReturn(false);
|
||||
when(results['pub']).thenReturn(true);
|
||||
when(results.wasParsed('out')).thenReturn(true);
|
||||
when(results['out']).thenReturn(temp.path);
|
||||
await handler.processArgResults(results);
|
||||
String path = p.join(temp.path, 'lib/main.dart');
|
||||
InitCommand command = new InitCommand();
|
||||
CommandRunner runner = new CommandRunner('test_flutter', '')
|
||||
..addCommand(command);
|
||||
await runner.run(['init', '--out', temp.path])
|
||||
.then((int code) => expect(code, equals(0)));
|
||||
|
||||
String path = p.join(temp.path, 'lib', 'main.dart');
|
||||
expect(new File(path).existsSync(), true);
|
||||
ProcessResult exec = Process.runSync(
|
||||
'dartanalyzer', ['--fatal-warnings', path],
|
||||
|
@ -4,9 +4,10 @@
|
||||
|
||||
library install_test;
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:sky_tools/src/install.dart';
|
||||
import 'package:sky_tools/src/application_package.dart';
|
||||
import 'package:sky_tools/src/install.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'src/common.dart';
|
||||
@ -23,12 +24,11 @@ defineTests() {
|
||||
MockAndroidDevice android = new MockAndroidDevice();
|
||||
when(android.isConnected()).thenReturn(true);
|
||||
when(android.installApp(any)).thenReturn(true);
|
||||
InstallCommandHandler handler = new InstallCommandHandler(android);
|
||||
InstallCommand command = new InstallCommand(android);
|
||||
|
||||
MockArgResults results = new MockArgResults();
|
||||
when(results['help']).thenReturn(false);
|
||||
handler
|
||||
.processArgResults(results)
|
||||
CommandRunner runner = new CommandRunner('test_flutter', '')
|
||||
..addCommand(command);
|
||||
runner.run(['install'])
|
||||
.then((int code) => expect(code, equals(0)));
|
||||
});
|
||||
});
|
||||
|
@ -2,15 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:sky_tools/src/device.dart';
|
||||
|
||||
class MockArgResults extends Mock implements ArgResults {
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
}
|
||||
|
||||
class MockAndroidDevice extends Mock implements AndroidDevice {
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
|
Loading…
x
Reference in New Issue
Block a user