run method

  1. @override
bool run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
bool run() {
  var argResults = this.argResults!;
  var stringUris = argResults.rest;
  if (stringUris.isEmpty) {
    stderr.writeln('Expected at least one uri for a node to inspect.');
  }
  for (var stringUri in stringUris) {
    var id = _idFromString(stringUri);
    if (id == null) {
      continue;
    }
    var node = assetGraph.get(id);
    if (node == null) {
      stderr.writeln('Unable to find an asset node for $stringUri.');
      continue;
    }

    var description = StringBuffer()
      ..writeln('Asset: $stringUri')
      ..writeln('  type: ${node.runtimeType}');

    if (node is GeneratedAssetNode) {
      description
        ..writeln('  state: ${node.state}')
        ..writeln('  wasOutput: ${node.wasOutput}')
        ..writeln('  phase: ${node.phaseNumber}')
        ..writeln('  isFailure: ${node.isFailure}');
    }

    void _printAsset(AssetId asset) =>
        _listAsset(asset, description, indentation: '    ');

    if (argResults['verbose'] == true) {
      description.writeln('  primary outputs:');
      node.primaryOutputs.forEach(_printAsset);

      description.writeln('  secondary outputs:');
      node.outputs.difference(node.primaryOutputs).forEach(_printAsset);

      if (node is NodeWithInputs) {
        description.writeln('  inputs:');
        assetGraph.allNodes
            .where((n) => n.outputs.contains(node.id))
            .map((n) => n.id)
            .forEach(_printAsset);
      }
    }

    stdout.write(description);
  }
  return false;
}