currentDpkCommand function

List<String> currentDpkCommand({
  1. String? workingDirectory,
})

The command line that starts the dpk that is running now.

For a compiled binary, such as one from dart install dpk, it is the binary. For dpk running on the Dart VM, as with dart run bin/dpk.dart or a snapshot, it is the dart executable, its VM options, and the script. A relative --packages path is made absolute against workingDirectory, so the command works from any directory.

Implementation

List<String> currentDpkCommand({String? workingDirectory}) {
  final executable = Platform.resolvedExecutable;
  final script = Platform.script.toFilePath();
  if (const bool.fromEnvironment('dart.vm.product') ||
      _samePath(executable, script)) {
    return [executable];
  }

  final base = workingDirectory ?? Directory.current.path;
  return [
    executable,
    for (final option in Platform.executableArguments)
      if (option.startsWith('--packages='))
        '--packages=${p.normalize(p.join(base, option.substring('--packages='.length)))}'
      else if (!option.startsWith('--resolved_executable_name=') &&
          !option.startsWith('--executable_name='))
        option,
    script,
  ];
}