mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

This initial version assumes the developer has mojo_shell and all other services sitting on disk somewhere and that they're on linux and only want to run on linux. This can be generalized down the line to support more use cases. This downloads the sky_viewer.mojo corresponding to the packages/sky_engine/REVISION in the developer's directory, so they can specify whatever revision they want. sky_tools run_mojo downloads sky_viewer.mojo into its cache directory if it is not present and constructs a command line to pass to mojo_shell that maps the shebang stamped into the flx to the downloaded sky_viewer.mojo. Since sky_viewer.mojo lives in the cloud and mojo_shell can load from the cloud this could also map to an https URL. This should likely be an option.
99 lines
2.7 KiB
Dart
99 lines
2.7 KiB
Dart
// 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:io';
|
|
|
|
import 'package:args/args.dart';
|
|
import 'package:logging/logging.dart';
|
|
import 'package:sky_tools/src/build.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';
|
|
|
|
void main(List<String> args) {
|
|
Logger.root.level = Level.WARNING;
|
|
Logger.root.onRecord.listen((LogRecord rec) {
|
|
print('${rec.level.name}: ${rec.message}');
|
|
if (rec.error != null) {
|
|
print(rec.error);
|
|
}
|
|
if (rec.stackTrace != null) {
|
|
print(rec.stackTrace);
|
|
}
|
|
});
|
|
|
|
Map<String, CommandHandler> handlers = {};
|
|
|
|
ArgParser parser = new ArgParser();
|
|
parser.addSeparator('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('commands:');
|
|
|
|
for (CommandHandler handler in [
|
|
new BuildCommandHandler(),
|
|
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;
|
|
}
|
|
|
|
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 _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}');
|
|
});
|
|
}
|