Skip to content

Commit

Permalink
Adjustment on which command
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Oct 4, 2023
1 parent b8ef172 commit 28c578c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
24 changes: 14 additions & 10 deletions lib/src/commands/global_command.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
11 changes: 8 additions & 3 deletions lib/src/utils/which.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,15 +23,17 @@ 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) {
for (var ext in possibleExtensions) {
String winPath = '$fullPath$ext';
exec = File(winPath);
if (exec.existsSync()) {
return exec.absolute.path;
final exectPath = exec.absolute.path;
return binDir ? dirname(exectPath) : exectPath;
}
}
}
Expand Down

0 comments on commit 28c578c

Please sign in to comment.