From 78d7431d3e12fdc45c725e1837acf9a694f6492e Mon Sep 17 00:00:00 2001 From: Yelaman Yelmuratov Date: Sat, 18 May 2024 23:09:05 +0500 Subject: [PATCH] . r command where for Windows --- lib/src/core/utils/utils.dart | 11 +++++++++-- lib/src/reporters/diff_tool/diff_info.dart | 2 ++ lib/src/reporters/diff_tool/diff_tool_reporter.dart | 2 +- lib/src/reporters/diff_tool/diff_tools.dart | 6 ++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/src/core/utils/utils.dart b/lib/src/core/utils/utils.dart index ff70076..075ef41 100644 --- a/lib/src/core/utils/utils.dart +++ b/lib/src/core/utils/utils.dart @@ -7,8 +7,7 @@ final class ApprovalUtils { final int green = int.parse(hex.substring(2, 4), radix: 16); final int blue = int.parse(hex.substring(4, 6), radix: 16); - final AnsiPen pen = AnsiPen() - ..rgb(r: red / 255, g: green / 255, b: blue / 255); + final AnsiPen pen = AnsiPen()..rgb(r: red / 255, g: green / 255, b: blue / 255); return pen; } @@ -50,4 +49,12 @@ final class ApprovalUtils { rethrow; } } + + static String get commandWhere { + if (Platform.isWindows) { + return 'where'; + } else { + return 'which'; + } + } } diff --git a/lib/src/reporters/diff_tool/diff_info.dart b/lib/src/reporters/diff_tool/diff_info.dart index c171fc8..6034a6b 100644 --- a/lib/src/reporters/diff_tool/diff_info.dart +++ b/lib/src/reporters/diff_tool/diff_info.dart @@ -4,9 +4,11 @@ part of '../../../../approval_tests.dart'; class DiffInfo { final String command; final String arg; + final String name; const DiffInfo({ required this.command, required this.arg, + required this.name, }); } diff --git a/lib/src/reporters/diff_tool/diff_tool_reporter.dart b/lib/src/reporters/diff_tool/diff_tool_reporter.dart index 4665612..efdb1ce 100644 --- a/lib/src/reporters/diff_tool/diff_tool_reporter.dart +++ b/lib/src/reporters/diff_tool/diff_tool_reporter.dart @@ -32,7 +32,7 @@ class DiffReporter implements Reporter { rethrow; } if (e is ProcessException) { - final ProcessResult result = await Process.run('which', ['code']); + final ProcessResult result = await Process.run(ApprovalUtils.commandWhere, [diffInfo.command]); ApprovalLogger.exception( 'Error during comparison via ${ide.name}. Please try check path of IDE. \n Current path: ${diffInfo.command} with arg: "${diffInfo.arg}" \n Path to IDE (${Platform.operatingSystem}): ${result.stdout} \n Please, add path to customDiffInfo.', stackTrace: st, diff --git a/lib/src/reporters/diff_tool/diff_tools.dart b/lib/src/reporters/diff_tool/diff_tools.dart index 189c591..6f802db 100644 --- a/lib/src/reporters/diff_tool/diff_tools.dart +++ b/lib/src/reporters/diff_tool/diff_tools.dart @@ -5,11 +5,13 @@ final class MacDiffTools { static const DiffInfo visualStudioCode = DiffInfo( command: '/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code', arg: '-d', + name: 'code', ); static const DiffInfo androidStudio = DiffInfo( command: '/Applications/Android Studio.app/Contents/MacOS/studio', arg: 'diff', + name: 'studio', ); } @@ -18,12 +20,14 @@ final class WindowsDiffTools { static const DiffInfo visualStudioCode = DiffInfo( command: 'C:\\Program Files\\Microsoft VS Code\\Code.exe', arg: '-d', + name: 'code', ); // TODO: check correct path for Android Studio on Windows static const DiffInfo androidStudio = DiffInfo( command: 'C:\\Program Files\\Android\\Android Studio\\bin\\studio64.exe', arg: 'diff', + name: 'studio', ); } @@ -33,11 +37,13 @@ final class LinuxDiffTools { static const DiffInfo visualStudioCode = DiffInfo( command: '/snap/bin/code', arg: '-d', + name: 'code', ); // TODO: check correct path for Android Studio on Linux static const DiffInfo androidStudio = DiffInfo( command: '/snap/bin/studio', arg: 'diff', + name: 'studio', ); }