Skip to content

Commit

Permalink
Merge pull request #654 from Bassiuz/main
Browse files Browse the repository at this point in the history
Add skipping version mismatch handling when using force or running with a custom fvm version.
  • Loading branch information
leoafarias authored Feb 27, 2024
2 parents bc02bba + c121121 commit 8ad0027
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased
## 3.0.12

* Adds skipping version mismatch handling when using force or running with a custom fvm version. [#653](https://github.com/leoafarias/fvm/issues/653)
* Fixes parsing error of vscode settings when there are commas [#656](https://github.com/leoafarias/fvm/issues/656)

## 3.0.11
Expand Down
2 changes: 1 addition & 1 deletion lib/src/commands/use_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class UseCommand extends BaseCommand {
}
}

final cacheVersion = await ensureCacheWorkflow(version);
final cacheVersion = await ensureCacheWorkflow(version, force: forceOption);

/// Run use workflow
await useVersionWorkflow(
Expand Down
16 changes: 13 additions & 3 deletions lib/src/workflows/ensure_cache.workflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import '../utils/helpers.dart';
Future<CacheFlutterVersion> ensureCacheWorkflow(
String version, {
bool shouldInstall = false,
bool force = false,
}) async {
_validateContext();
// Get valid flutter version
final validVersion = await validateFlutterVersion(version);
final validVersion = await validateFlutterVersion(version, force: force);
try {
final cacheVersion = CacheService.fromContext.getVersion(validVersion);

Expand All @@ -36,8 +37,12 @@ Future<CacheFlutterVersion> ensureCacheWorkflow(
);
}

if (integrity == CacheIntegrity.versionMismatch) {
if (integrity == CacheIntegrity.versionMismatch && !force && !validVersion.isCustom) {
return await _handleVersionMismatch(cacheVersion);
} else if (force) {
logger.warn('Not checking for version mismatch as --force flag is set.');
} else if (validVersion.isCustom) {
logger.warn('Not checking for version mismatch as custom version is being used.');
}

// If shouldl install notifiy the user that is already installed
Expand Down Expand Up @@ -160,8 +165,13 @@ Future<CacheFlutterVersion> _handleVersionMismatch(
return ensureCacheWorkflow(version.name, shouldInstall: true);
}

Future<FlutterVersion> validateFlutterVersion(String version) async {
Future<FlutterVersion> validateFlutterVersion(String version, {bool force = false}) async {
final flutterVersion = FlutterVersion.parse(version);

if (force) {
return flutterVersion;
}

// If its channel or commit no need for further validation
if (flutterVersion.isChannel || flutterVersion.isCustom) {
return flutterVersion;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: fvm
description: A simple cli to manage Flutter SDK versions per project. Support
channels, releases, and local cache for fast switching between versions.
version: 3.0.11
version: 3.0.12
homepage: https://github.com/leoafarias/fvm

environment:
Expand Down

0 comments on commit 8ad0027

Please sign in to comment.