scriptHeader method

String scriptHeader(
  1. String executableName, {
  2. bool viaOption = false,
  3. String? commandName,
})

The comment lines for the header of the generated script: what generated it, how to install it (installInstructions) and why it needs to be installed only once.

Implementation

String scriptHeader(
  final String executableName, {
  final bool viaOption = false,
  final String? commandName,
}) {
  final exe = executableName;
  final name = commandName ?? exe;
  final lines = [
    'Generated by `${scriptCommand(exe, viaOption: viaOption, commandName: commandName)}`.',
    ...installInstructions(
      exe,
      viaOption: viaOption,
      commandName: commandName,
    ).split('\n'),
    '',
    'The script contains no commands or options. The completion alternatives',
    if (name == exe)
      'are requested from the executable (`$exe __complete ...`), so it keeps'
    else
      'are requested from $exe directly (`$exe __complete ...`), so it keeps',
    'working when the executable is updated.',
  ];
  return lines.map((final l) => l.isEmpty ? '#' : '# $l').join('\n');
}