| // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
| // for details. 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:kernel/kernel.dart'; | |
| class CommandLineHelper { | |
| static void requireExactlyOneArgument( | |
| List<String> args, void Function() usage, | |
| {bool requireFileExists = false}) { | |
| if (args.length != 1) { | |
| print("Expected exactly 1 argument, got ${args.length}."); | |
| usage(); | |
| } | |
| if (requireFileExists) CommandLineHelper.requireFileExists(args[0]); | |
| } | |
| static void requireVariableArgumentCount( | |
| List<int> ok, List<String> args, void Function() usage) { | |
| if (!ok.contains(args.length)) { | |
| print("Expected the argument count to be one of ${ok}, got " | |
| "${args.length}."); | |
| usage(); | |
| } | |
| } | |
| static void requireFileExists(String file) { | |
| if (!new File(file).existsSync()) { | |
| print("File $file doesn't exist."); | |
| exit(1); | |
| } | |
| } | |
| static Component tryLoadDill(String file) { | |
| try { | |
| return loadComponentFromBinary(file); | |
| } catch (e, s) { | |
| print("$file can't be loaded:"); | |
| print('$e\n$s'); | |
| exit(1); | |
| } | |
| } | |
| } |