-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from leoafarias/feature/detached-notice
Command detach check
- Loading branch information
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,49 @@ | ||
import 'dart:io' show Platform; | ||
|
||
import 'package:io/io.dart'; | ||
|
||
import '../../constants.dart'; | ||
import '../../exceptions.dart'; | ||
import 'logger.dart'; | ||
|
||
/// Guards against certain action by validatin and throwing errors | ||
class Guards { | ||
Guards._(); | ||
|
||
/// Check if can execute path or throws error | ||
static Future<void> canExecute(String execPath) async { | ||
static Future<void> canExecute(String execPath, List<String> args) async { | ||
if (!await isExecutable(execPath)) { | ||
throw FvmInternalError('Cannot execute $execPath'); | ||
} | ||
if (Guards.shouldRunDetached(args)) { | ||
logger.trace(Platform.script.path); | ||
FvmLogger.spacer(); | ||
FvmLogger.info( | ||
'This command ${args.join(" ")} will modify FVM installation.', | ||
); | ||
FvmLogger.info( | ||
'''Because of that is suggested you run the following command in your terminal directly''', | ||
); | ||
FvmLogger.spacer(); | ||
FvmLogger.fine("$execPath ${args.join(' ')}"); | ||
|
||
FvmLogger.spacer(); | ||
|
||
FvmLogger.info( | ||
'''If after this command FVM cannot be found in your terminal. Please run the following:''', | ||
); | ||
|
||
FvmLogger.spacer(); | ||
FvmLogger.fine("$execPath pub global activate fvm"); | ||
|
||
throw FvmUsageException('Command needs to run outside of FVM proxy'); | ||
} | ||
} | ||
|
||
/// Check if command needs to be run detached | ||
static bool shouldRunDetached(List<String> args) { | ||
final argString = args.join(' '); | ||
|
||
return kDetachedCommands.any(argString.contains); | ||
} | ||
} |