toValidate method

Future<String> toValidate({
  1. bool removing = false,
})

Generates a script to validate the package installation.

The script is generated based on the current operating system and package manager.

If removing is true, the script will validate the package removal instead of installation.

Implementation

Future<String> toValidate({bool removing = false}) async {
  await boot();

  String? bestValidateExecutable;

  final String? firstProvides = await packageScript.getFirstProvides();
  if (firstProvides != null) {
    final firstProvidesExecutable = await Executable(firstProvides).find(cache: false);
    if (firstProvidesExecutable != null) {
      bestValidateExecutable = firstProvidesExecutable;
    }
  }
  if (bestValidateExecutable == null) {
    final String? nameExecutable = await Executable(packageName).find(cache: false);
    if (nameExecutable != null) {
      bestValidateExecutable = nameExecutable;
    }
  }

  String togetherContents =
      '''
#!/usr/bin/env bash

${await dynamicCode()}

${await baseScriptContents()}

${await packageScript.contents()}

validate "$bestValidateExecutable"
''';

  return (await writeThisBeast(togetherContents)).path;
}