Commit 384ded5b authored by Ian Fischer's avatar Ian Fischer

Begin refactoring API around CommandHandlers and using it consistently in subclasses.

Also applies autoreformatting to init.dart.
parent f4ed42e5
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async';
import 'package:args/args.dart'; import 'package:args/args.dart';
abstract class CommandHandler { abstract class CommandHandler {
...@@ -12,7 +14,7 @@ abstract class CommandHandler { ...@@ -12,7 +14,7 @@ abstract class CommandHandler {
ArgParser get parser; ArgParser get parser;
void processArgResults(ArgResults results); Future<int> processArgResults(ArgResults results);
void printUsage([String message]) { void printUsage([String message]) {
if (message != null) { if (message != null) {
......
...@@ -22,20 +22,22 @@ class InitCommandHandler extends CommandHandler { ...@@ -22,20 +22,22 @@ class InitCommandHandler extends CommandHandler {
parser.addFlag('help', parser.addFlag('help',
abbr: 'h', negatable: false, help: 'Display this help message.'); abbr: 'h', negatable: false, help: 'Display this help message.');
parser.addOption('out', abbr: 'o', help: 'The output directory.'); parser.addOption('out', abbr: 'o', help: 'The output directory.');
parser.addFlag('pub', defaultsTo: true, parser.addFlag('pub',
defaultsTo: true,
help: 'Whether to run pub after the project has been created.'); help: 'Whether to run pub after the project has been created.');
return parser; return parser;
} }
Future processArgResults(ArgResults results) async { @override
Future<int> processArgResults(ArgResults results) async {
if (results['help']) { if (results['help']) {
printUsage(); printUsage();
return new Future.value(); return 0;
} }
if (!results.wasParsed('out')) { if (!results.wasParsed('out')) {
printUsage('No option specified for the output directory.'); printUsage('No option specified for the output directory.');
return new Future.value(); return 2;
} }
// TODO: Confirm overwrite of an existing directory with the user. // TODO: Confirm overwrite of an existing directory with the user.
...@@ -58,7 +60,8 @@ Or if the Sky APK is not already on your device, run: ...@@ -58,7 +60,8 @@ Or if the Sky APK is not already on your device, run:
if (results['pub']) { if (results['pub']) {
print("Running pub get..."); print("Running pub get...");
Process process = await Process.start('pub', ['get'], workingDirectory: out.path); Process process =
await Process.start('pub', ['get'], workingDirectory: out.path);
stdout.addStream(process.stdout); stdout.addStream(process.stdout);
stderr.addStream(process.stderr); stderr.addStream(process.stderr);
int code = await process.exitCode; int code = await process.exitCode;
...@@ -67,7 +70,9 @@ Or if the Sky APK is not already on your device, run: ...@@ -67,7 +70,9 @@ Or if the Sky APK is not already on your device, run:
} }
} else { } else {
print(message); print(message);
return 2;
} }
return 0;
} }
} }
...@@ -85,10 +90,7 @@ abstract class Template { ...@@ -85,10 +90,7 @@ abstract class Template {
dir.createSync(recursive: true); dir.createSync(recursive: true);
files.forEach((String path, String contents) { files.forEach((String path, String contents) {
Map m = { Map m = {'projectName': projectName, 'description': description};
'projectName': projectName,
'description': description
};
contents = mustache.render(contents, m); contents = mustache.render(contents, m);
File file = new File(p.join(dir.path, path)); File file = new File(p.join(dir.path, path));
file.parent.createSync(); file.parent.createSync();
...@@ -102,10 +104,10 @@ abstract class Template { ...@@ -102,10 +104,10 @@ abstract class Template {
class SkySimpleTemplate extends Template { class SkySimpleTemplate extends Template {
SkySimpleTemplate() : super('sky-simple', 'A minimal Sky project.') { SkySimpleTemplate() : super('sky-simple', 'A minimal Sky project.') {
files['.gitignore']= _gitignore; files['.gitignore'] = _gitignore;
files['pubspec.yaml']= _pubspec; files['pubspec.yaml'] = _pubspec;
files['README.md']= _readme; files['README.md'] = _readme;
files['lib/main.dart']= _libMain; files['lib/main.dart'] = _libMain;
} }
} }
......
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