Skip to content

Commit

Permalink
Added better skip behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Feb 16, 2024
1 parent 3cdd202 commit a7a1b03
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
3 changes: 2 additions & 1 deletion lib/src/commands/install_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class InstallCommand extends BaseCommand {
await useVersionWorkflow(
version: cacheVersion,
project: project,
skipSetup: false,
force: true,
skipSetup: !setup,
);

return ExitCode.success.code;
Expand Down
11 changes: 9 additions & 2 deletions lib/src/workflows/resolve_dependencies.workflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import '../utils/exceptions.dart';

Future<void> resolveDependenciesWorkflow(
Project project,
CacheFlutterVersion version,
) async {
CacheFlutterVersion version, {
required bool force,
}) async {
if (version.notSetup) return;

if (project.dartToolVersion == version.flutterSdkVersion) {
Expand Down Expand Up @@ -49,6 +50,12 @@ Future<void> 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?',
);
Expand Down
35 changes: 26 additions & 9 deletions lib/src/workflows/use_version.workflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ Future<void> useVersionWorkflow({
}

// Checks if the project constraints are met
_checkProjectVersionConstraints(project, version);
_checkProjectVersionConstraints(project, version, force: force);

final updatedProject = ProjectService.fromContext.update(
project,
flavors: {if (flavor != null) flavor: version.name},
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
Expand Down Expand Up @@ -101,7 +101,7 @@ Future<void> useVersionWorkflow({
///
/// The method prompts the user for confirmation before actually adding the path,
/// unless running in a test environment.
Future<void> _checkGitignore(Project project) async {
Future<void> _checkGitignore(Project project, {required bool force}) async {
logger.detail('Checking .gitignore');

final updateGitIgnore = project.config?.updateGitIgnore ?? true;
Expand Down Expand Up @@ -160,9 +160,17 @@ Future<void> _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
Expand All @@ -177,8 +185,9 @@ Future<void> _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;

Expand Down Expand Up @@ -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.',
Expand Down Expand Up @@ -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'));
Expand Down

0 comments on commit a7a1b03

Please sign in to comment.