run method
Runs this command as a leaf command. Implemented by subclasses.
Implementation
@override
Future<T?> run(
final CommandContext<CompletionInstallOption, T> context,
) async {
final request = _CompletionRequest.of(context);
final dryRun = context.config.value(CompletionInstallOption.dryRun);
// The script is saved in a file named after the command: a path
// would name a file elsewhere.
final commandName = request.commandName;
if (commandName != null &&
!CompletionInstaller.isCommandName(commandName)) {
_reportUsageError(
context,
'Cannot install the completion for "$commandName". '
'Specify the name of the command with --command, not its path.',
);
}
final steps = (_installer ?? CompletionInstaller()).plan(
request.shell,
name: request.name,
script: request.script,
executableName: request.runner.executableName,
);
final out = request.runner.completion.sinks.out;
out.writeln(
'Installing the ${request.shell.displayName} completion '
'for ${request.name}${dryRun ? ' (dry run, nothing is changed)' : ''}:',
);
for (final step in steps) {
out.writeln(' ${step.description.replaceAll('\n', '\n ')}');
if (!dryRun) step.perform();
}
if (!dryRun) out.writeln(request.shell.activationInstruction);
return null;
}