main function
Implementation
Future<void> main(List<String> args) async {
final logSubscription =
Logger.root.onRecord.listen((record) => print(record.message));
logger.warning(
'Warning: this tool is unsupported and usage may change at any time, '
'use at your own risk.');
final argParser = ArgParser()
..addOption('graph-file',
abbr: 'g', help: 'Specify the asset_graph.json file to inspect.')
..addOption('build-script',
abbr: 'b',
help: 'Specify the build script to find the asset graph for.',
defaultsTo: '.dart_tool/build/entrypoint/build.dart');
final results = argParser.parse(args);
if (results.wasParsed('graph-file') && results.wasParsed('build-script')) {
throw ArgumentError(
'Expected exactly one of `--graph-file` or `--build-script`.');
}
var assetGraphFile = File(_findAssetGraph(results));
if (!assetGraphFile.existsSync()) {
throw ArgumentError('Unable to find AssetGraph.');
}
stdout.writeln('Loading asset graph at ${assetGraphFile.path}...');
assetGraph = AssetGraph.deserialize(assetGraphFile.readAsBytesSync());
packageGraph = await PackageGraph.forThisPackage();
var commandRunner = CommandRunner<bool>(
'', 'A tool for inspecting the AssetGraph for your build')
..addCommand(InspectNodeCommand())
..addCommand(GraphCommand())
..addCommand(QuitCommand());
stdout.writeln('Ready, please type in a command:');
var shouldExit = false;
while (!shouldExit) {
stdout
..writeln('')
..write('> ');
var nextCommand = stdin.readLineSync();
stdout.writeln('');
try {
shouldExit = await commandRunner.run(nextCommand!.split(' ')) ?? true;
} on UsageException {
stdout.writeln('Unrecognized option');
await commandRunner.run(['help']);
}
}
await logSubscription.cancel();
}