From a7a1b03007c2cd837625822283a5249dc5b89ebb Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Fri, 16 Feb 2024 11:20:08 -0500 Subject: [PATCH] Added better skip behavior --- lib/src/commands/install_command.dart | 3 +- .../resolve_dependencies.workflow.dart | 11 ++++-- lib/src/workflows/use_version.workflow.dart | 35 ++++++++++++++----- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/lib/src/commands/install_command.dart b/lib/src/commands/install_command.dart index 80efceb4..bdfb4a44 100644 --- a/lib/src/commands/install_command.dart +++ b/lib/src/commands/install_command.dart @@ -55,7 +55,8 @@ class InstallCommand extends BaseCommand { await useVersionWorkflow( version: cacheVersion, project: project, - skipSetup: false, + force: true, + skipSetup: !setup, ); return ExitCode.success.code; diff --git a/lib/src/workflows/resolve_dependencies.workflow.dart b/lib/src/workflows/resolve_dependencies.workflow.dart index 39037df9..509a1c51 100644 --- a/lib/src/workflows/resolve_dependencies.workflow.dart +++ b/lib/src/workflows/resolve_dependencies.workflow.dart @@ -9,8 +9,9 @@ import '../utils/exceptions.dart'; Future resolveDependenciesWorkflow( Project project, - CacheFlutterVersion version, -) async { + CacheFlutterVersion version, { + required bool force, +}) async { if (version.notSetup) return; if (project.dartToolVersion == version.flutterSdkVersion) { @@ -49,6 +50,12 @@ Future resolveDependenciesWorkflow( 'The error could indicate incompatible dependencies to the SDK.', ); + if (force) { + logger.warn('Force pinning due to --force flag.'); + + return; + } + final confirmation = logger.confirm( 'Would you like to continue pinning this version anyway?', ); diff --git a/lib/src/workflows/use_version.workflow.dart b/lib/src/workflows/use_version.workflow.dart index 7f80dbea..5b9f3eb5 100644 --- a/lib/src/workflows/use_version.workflow.dart +++ b/lib/src/workflows/use_version.workflow.dart @@ -51,7 +51,7 @@ Future useVersionWorkflow({ } // Checks if the project constraints are met - _checkProjectVersionConstraints(project, version); + _checkProjectVersionConstraints(project, version, force: force); final updatedProject = ProjectService.fromContext.update( project, @@ -59,14 +59,14 @@ Future useVersionWorkflow({ flutterSdkVersion: version.name, ); - await _checkGitignore(updatedProject); + await _checkGitignore(updatedProject, force: force); - await resolveDependenciesWorkflow(updatedProject, version); + await resolveDependenciesWorkflow(updatedProject, version, force: force); _updateLocalSdkReference(updatedProject, version); _updateCurrentSdkReference(updatedProject, version); - _manageVscodeSettings(updatedProject); + _manageVsCodeSettings(updatedProject); final versionLabel = cyan.wrap(version.printFriendlyName); // Different message if configured environment @@ -101,7 +101,7 @@ Future useVersionWorkflow({ /// /// The method prompts the user for confirmation before actually adding the path, /// unless running in a test environment. -Future _checkGitignore(Project project) async { +Future _checkGitignore(Project project, {required bool force}) async { logger.detail('Checking .gitignore'); final updateGitIgnore = project.config?.updateGitIgnore ?? true; @@ -160,9 +160,17 @@ Future _checkGitignore(Project project) async { }); logger.info( - 'You should add the $kPackageName version directory "${cyan.wrap(pathToAdd)}" to .gitignore?', + 'You should add the $kPackageName version directory "${cyan.wrap(pathToAdd)}" to .gitignore.', ); + if (force) { + logger.warn( + 'Skipping .gitignore confirmation because of --force flag detected', + ); + + return; + } + if (logger.confirm('Would you like to do that now?', defaultValue: true)) { ignoreFile.writeAsStringSync(lines.join('\n'), mode: FileMode.write); logger @@ -177,8 +185,9 @@ Future _checkGitignore(Project project) async { /// parameter is the cached version of the Flutter SDK. void _checkProjectVersionConstraints( Project project, - CacheFlutterVersion cachedVersion, -) { + CacheFlutterVersion cachedVersion, { + required bool force, +}) { final sdkVersion = cachedVersion.dartSdkVersion; final constraints = project.sdkConstraint; @@ -212,6 +221,14 @@ void _checkProjectVersionConstraints( ..info('This could cause unexpected behavior or issues.') ..spacer; + if (force) { + logger.warn( + 'Skipping version constraint confirmation because of --force flag detected', + ); + + return; + } + if (!logger.confirm('Would you like to proceed?', defaultValue: true)) { throw AppException( 'The Flutter SDK version $sdkVersion is not compatible with the project constraints. You may need to adjust the version to avoid potential issues.', @@ -272,7 +289,7 @@ void _updateCurrentSdkReference(Project project, CacheFlutterVersion version) { /// the .fvm/versions directory from search and file watchers./// /// The method also updates the "dart.flutterSdkPath" setting to use the relative /// path of the .fvm symlink. -void _manageVscodeSettings(Project project) { +void _manageVsCodeSettings(Project project) { final updateVscodeSettings = project.config?.updateVscodeSettings ?? true; final vscodeDir = Directory(join(project.path, '.vscode'));