update static method

Future<void> update([
  1. bool isGit = false,
  2. bool forceUpdate = false
])

Implementation

static Future<void> update(
    [bool isGit = false, bool forceUpdate = false]) async {
  isGit = FutureCli.arguments.contains('--git');
  forceUpdate = FutureCli.arguments.contains('-f');
  if (!isGit && !forceUpdate) {
    var versionInPubDev =
        await PubDevApi.getLatestVersionFromPackage('get_cli');

    var versionInstalled = await PubspecLock.getVersionCli(disableLog: true);

    if (versionInstalled == versionInPubDev) {
      return LogService.info(
          Translation(LocaleKeys.info_cli_last_version_already_installed.tr)
              .toString());
    }
  }

  LogService.info('Upgrading get_cli …');

  try {
    if (Platform.script.path.contains('flutter')) {
      if (isGit) {
        await run(
            'flutter pub global activate -sgit https://github.com/jonataslaw/get_cli/',
            verbose: true);
      } else {
        await run('flutter pub global activate get_cli', verbose: true);
      }
    } else {
      if (isGit) {
        await run(
            'flutter pub global activate -sgit https://github.com/jonataslaw/get_cli/',
            verbose: true);
      } else {
        await run('flutter pub global activate get_cli', verbose: true);
      }
    }
    return LogService.success(LocaleKeys.sucess_update_cli.tr);
  } on Exception catch (err) {
    LogService.info(err.toString());
    return LogService.error(LocaleKeys.error_update_cli.tr);
  }
}