From 28c578cdbd0cde5ada5aaac653f89c378e1a2251 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Wed, 4 Oct 2023 11:08:31 -0400 Subject: [PATCH] Adjustment on which command --- lib/src/commands/global_command.dart | 24 ++++++++++++++---------- lib/src/utils/which.dart | 11 ++++++++--- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/src/commands/global_command.dart b/lib/src/commands/global_command.dart index 493f9f63..68813d4b 100644 --- a/lib/src/commands/global_command.dart +++ b/lib/src/commands/global_command.dart @@ -1,10 +1,11 @@ +import 'package:fvm/constants.dart'; import 'package:fvm/src/models/cache_flutter_version_model.dart'; -import 'package:fvm/src/models/flutter_version_model.dart'; import 'package:fvm/src/services/global_version_service.dart'; import 'package:fvm/src/services/logger_service.dart'; import 'package:fvm/src/services/project_service.dart'; import 'package:fvm/src/utils/console_utils.dart'; import 'package:fvm/src/utils/context.dart'; +import 'package:fvm/src/utils/helpers.dart'; import 'package:fvm/src/utils/which.dart'; import 'package:mason_logger/mason_logger.dart'; import 'package:tint/tint.dart'; @@ -46,19 +47,18 @@ class GlobalCommand extends BaseCommand { // Sets version as the global GlobalVersionService.fromContext.setGlobal(cacheVersion); - final flutterInPath = which('flutter'); + final flutterInPath = which('flutter', binDir: true); // Get pinned version, for comparison on terminal - final pinnedVersion = ProjectService.fromContext.findVersion(); + final project = ProjectService.fromContext.findAncestor(); + + final pinnedVersion = project.pinnedVersion; CacheFlutterVersion? pinnedCacheVersion; if (pinnedVersion != null) { //TODO: Should run validation on this - final flutterPinnedVersion = FlutterVersion.parse(pinnedVersion); - pinnedCacheVersion = CacheService.fromContext.getVersion( - flutterPinnedVersion, - ); + pinnedCacheVersion = CacheService.fromContext.getVersion(pinnedVersion); } final isDefaultInPath = flutterInPath == ctx.globalCacheBinPath; @@ -93,9 +93,13 @@ class GlobalCommand extends BaseCommand { ..spacer; } - logger.info( - 'Your IDE might override the PATH to the Flutter in their terminal to the one configured within the project.', - ); + if (isVsCode()) { + logger + ..notice( + '$kVsCode might override the PATH to the Flutter in their terminal', + ) + ..info('Run the command outside of the IDE to verify.'); + } return ExitCode.success.code; } } diff --git a/lib/src/utils/which.dart b/lib/src/utils/which.dart index 90e98f59..b81fca21 100644 --- a/lib/src/utils/which.dart +++ b/lib/src/utils/which.dart @@ -2,7 +2,10 @@ import 'dart:io'; import 'package:path/path.dart'; -String? which(String command) { +String? which( + String command, { + bool binDir = false, +}) { String? pathEnv = Platform.environment['PATH']; String? pathExtEnv = Platform.isWindows ? Platform.environment['PATHEXT'] : null; @@ -20,7 +23,8 @@ String? which(String command) { File exec = File(fullPath); if (exec.existsSync()) { - return exec.absolute.path; + final exectPath = exec.absolute.path; + return binDir ? dirname(exectPath) : exectPath; } if (Platform.isWindows && pathExtEnv != null) { @@ -28,7 +32,8 @@ String? which(String command) { String winPath = '$fullPath$ext'; exec = File(winPath); if (exec.existsSync()) { - return exec.absolute.path; + final exectPath = exec.absolute.path; + return binDir ? dirname(exectPath) : exectPath; } } }