getLatestCLIVersionFromGitSync static method

String? getLatestCLIVersionFromGitSync()

Get version from Git synchronously (for fallback when pubspec.yaml not found locally)

Implementation

static String? getLatestCLIVersionFromGitSync() {
  try {
    // Try curl first (works on macOS/Linux)
    ProcessResult result = Process.runSync(
      'curl',
      ['-s', '--max-time', '5', 'https://raw.githubusercontent.com/victorsdd01/vgv_cli/main/pubspec.yaml'],
      runInShell: true,
    );

    if (result.exitCode != 0) {
      // Try wget as fallback (works on Linux)
      result = Process.runSync(
        'wget',
        ['-q', '--timeout=5', '-O', '-', 'https://raw.githubusercontent.com/victorsdd01/vgv_cli/main/pubspec.yaml'],
        runInShell: true,
      );
    }

    if (result.exitCode == 0 && result.stdout.toString().isNotEmpty) {
      final content = result.stdout.toString();
      final versionMatch = RegExp(r'version:\s*(\d+\.\d+\.\d+)').firstMatch(content);
      if (versionMatch != null) {
        return versionMatch.group(1)!;
      }
    }
  } catch (e) {
    // Silently fail - network issues shouldn't break the CLI
  }

  return null;
}