writeToShellConfigFile method

  1. @visibleForTesting
void writeToShellConfigFile(
  1. String rootCommand
)

Write a source to the completion global script in the shell configuration file, which its location is described by the configuration.

Implementation

@visibleForTesting
void writeToShellConfigFile(String rootCommand) {
  final configuration = this.configuration!;

  logger.info(
    'Adding dart cli completion config entry '
    'to $_shellRCFilePath',
  );

  final shellRCFile = File(_shellRCFilePath);
  if (!shellRCFile.existsSync()) {
    throw CompletionInstallationException(
      rootCommand: rootCommand,
      message: 'No configuration file found at ${shellRCFile.path}',
    );
  }

  if (const ScriptConfigurationEntry('Completion').existsIn(shellRCFile)) {
    logger.warn(
      '''A completion config entry was already found on $_shellRCFilePath.''',
    );
    return;
  }

  _sourceScriptOnFile(
    configFile: shellRCFile,
    scriptName: 'Completion',
    description: 'Completion scripts setup. '
        'Remove the following line to uninstall',
    scriptPath: path.join(
      completionConfigDir.path,
      configuration.completionConfigForShellFileName,
    ),
  );
}