run method

  1. @override
Future<void> run()
override

Runs this command.

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

Implementation

@override
Future<void> run() async {
  ensurePrerequisitesSatisfied();

  print('Using .tool-versions file to generate symlinks in .asdf');

  const toolVersionParser = ToolVersionParser();
  final toolVersions = toolVersionParser.run();

  final dotAsdfDir = Directory(join(Directory.current.path, '.asdf'));
  if (!dotAsdfDir.existsSync()) {
    dotAsdfDir.createSync(recursive: true);
  }

  for (final toolVersion in toolVersions.toolVersions) {
    // dart format off
    final toolPath = (Process.runSync(
      'asdf',
      ['where', toolVersion.tool],
      runInShell: true).stdout as String).trim();
    // dart format on

    final targetPath = join(
      Directory.current.path,
      '.asdf',
      toolVersion.tool,
    );

    print(
      Process.runSync('ln', [
        '-s',
        toolPath,
        targetPath,
      ], runInShell: true).stderr,
    );
  }

  print('Done');
}