isGloballyActivatedFromSource method Null safety

bool isGloballyActivatedFromSource(
  1. String packageName
)

Returns true if the the dart project packageName is running from local source. This means that the package has been activated via

dart pub global activate --source path <path to package>

Implementation

bool isGloballyActivatedFromSource(String packageName) {
  /// run pub global list to see if dcli is run from a local path.
  final line = DartSdk()
      .runPub(args: ['global', 'list'], progress: Progress.capture())
      .lines
      .firstWhere((line) => line.startsWith(packageName),
          orElse: () => packageName);

  return line.contains('at path');
}