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 {
  if (isProgramInstalled(SidekickContext.cliName)) {
    print('program ${SidekickContext.cliName} is already globally installed');
    exit(0);
  }

  /// The entrypoint injects its location
  GlobalSidekickRoot.linkBinary(SidekickContext.entryPoint);

  if (dcli.isOnPATH(GlobalSidekickRoot.binDir.path)) {
    print(
      "You can now use '${SidekickContext.cliName}' from everywhere\n",
    );
  } else {
    _addBinDirToPathOrPrint();
  }

  final String startScript = () {
    try {
      final path = Shell.current.pathToStartScript;
      if (path != null) {
        return path;
      }
    } catch (_) {
      // ignore
    }
    return '~/.bashrc';
  }();

  printerr('Run ${cyan('source $startScript')} or restart your terminal '
      'to activate tab completion');
}