bestForWindows method

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

Determines the best installation method for Windows.

The to parameter is the installation target.

Implementation

Future<String> bestForWindows({String to = 'install'}) async {
  // @TODO add support for global update (if possible)

  final methods = package.methods ?? [];
  final hasMethod = methods.contains('choco');

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

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

    late final String? bestWindows;

    if (choco != null) {
      bestWindows = '$choco -y';
      if (hasDefault) {
        return '$choco $to -y ${package.name}';
      }
    } else if (scoop != null) {
      // @TODO add support for hasDefault "scoop"
      bestWindows = '$scoop --yes';
    }

    if (bestWindows != null) {
      return '${to}_windows "$bestWindows"';
    }
  }

  stopIfForcedMethodNotFound();

  throw Exception('No package manager found for Windows');
}