bestForClearLinux method

Future<String> bestForClearLinux({
  1. String to = 'install',
})

Determines the best installation method for Clear Linux OS.

The to parameter is the installation target.

Implementation

Future<String> bestForClearLinux({String to = 'install'}) async {
  final methods = package.methods ?? [];
  final hasMethod = methods.contains('swupd');

  final defaults = package.defaults ?? [];
  final hasDefault = defaults.contains('swupd');

  if (hasMethod || hasDefault) {
    final swupd = await Executable('swupd').find();

    final String? bestSwupd = swupd;

    if (bestSwupd != null) {
      // Global.updateCommand = '${Global.sudoPath} $bestSwupd update || $errorOnUpdate';
      // @FIXME there is no update command for swupd only upgrade
      if (hasDefault) {
        final operation = to == 'install' ? 'bundle-add' : 'bundle-remove';
        return '${Global.sudoPath} $bestSwupd $operation -y ${package.name}';
      }
      return '${to}_swupd "${Global.sudoPath} $bestSwupd"';
    }
  }

  stopIfForcedMethodNotFound();

  return await bestForAny(to: to);
}