plan method

List<CompletionInstallStep> plan(
  1. CompletionShell shell, {
  2. required String name,
  3. required String script,
  4. required String executableName,
})

Plans the installation of script, the completion script of shell for the command name, and returns its steps in order.

Nothing is changed until the steps are performed. The steps are planned from the current state of the file system: directories that exist are not created, and a startup file that already loads the script is not changed.

executableName is named in the startup file as the origin of the lines added to it.

Throws an ArgumentError if name is not a command name, see isCommandName, and a FileSystemException if the user's home directory is unknown.

Implementation

List<CompletionInstallStep> plan(
  final CompletionShell shell, {
  required final String name,
  required final String script,
  required final String executableName,
}) {
  final scriptFile = scriptPath(shell, name);
  final startupFile = startupFilePath(shell);
  final plannedDirectories = <String>{};
  return [
    ..._createDirectory(_path.dirname(scriptFile), plannedDirectories),
    CompletionInstallStep(
      'Write $scriptFile',
      () => File(scriptFile).writeAsStringSync(script),
    ),
    if (startupFile != null)
      ..._addToStartupFile(startupFile, [
        '# $name shell completion, '
            'added by `$executableName completion install`.',
        ..._loadLines(shell, scriptFile),
      ], plannedDirectories),
  ];
}