Skip to content

Commit

Permalink
Improved ci behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Aug 25, 2024
1 parent ec45f17 commit 7d50e8e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 25 deletions.
11 changes: 1 addition & 10 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ import 'package:fvm/src/utils/context.dart';
import 'package:scope/scope.dart';

Future<void> main(List<String> args) async {
final editableArgs = List<String>.from(args);
final skipInput = editableArgs.remove('--fvm-skip-input');
final scope = Scope()
..value(
contextKey,
FVMContext.create(
args: editableArgs,
skipInput: skipInput,
),
);
final scope = Scope()..value(contextKey, FVMContext.create(args: args));

await _flushThenExit(
await scope.run(() async => FvmCommandRunner().run((args))),
Expand Down
18 changes: 8 additions & 10 deletions lib/src/services/logger_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ class LoggerService extends ContextService {
return progress;
}

bool confirm(String? message, {bool? defaultValue, bool? ciDefaultValue}) {
bool confirm(String? message, {required bool defaultValue}) {
// When running tests, always return true.
if (context.isTest) return true;

if (context.skipInput) {
if (ciDefaultValue != null) {
return ciDefaultValue;
} else if (defaultValue != null) {
return defaultValue;
}
exit(ExitCode.usage.code);
if (context.isCI || context.skipInput) {
logger.info(message ?? '');
logger
..warn('Skipping input confirmation')
..warn('Using default value of $defaultValue');

return defaultValue;
}

return interact.Confirm(prompt: message ?? '', defaultValue: defaultValue)
Expand Down Expand Up @@ -134,8 +134,6 @@ class LoggerService extends ContextService {
final dot = '\u{25CF}'; // ●
final rightArrow = '\u{2192}'; // →

/// Logger for FVM
/// Console controller instance
final consoleController = ConsoleController();

/// Console Controller
Expand Down
6 changes: 4 additions & 2 deletions lib/src/utils/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class FVMContext with FVMContextMappable {
static FVMContext create({
String? id,
List<String>? args,
bool? skipInput,
AppConfig? configOverrides,
String? workingDirectory,
Map<Type, dynamic>? generatorOverrides,
Expand All @@ -95,13 +94,16 @@ class FVMContext with FVMContextMappable {

final environment = {...Platform.environment, ...?environmentOverrides};

// Skips input if running in CI
final skipInput = args?.remove('--fvm-skip-input') ?? false;

return FVMContext.base(
id: id ?? 'MAIN',
workingDirectory: workingDirectory,
config: config,
environment: environment,
args: args ?? [],
skipInput: skipInput ?? false,
skipInput: skipInput,
generators: {
LoggerService: (context) => LoggerService(
level: level,
Expand Down
1 change: 1 addition & 0 deletions lib/src/utils/deprecation_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void _warnDeprecatedEnvVars() {
logger.info('Please use ${ConfigKeys.flutterUrl.envKey}');
final confirmation = logger.confirm(
'Do you want to proceed? This might impact the expected behavior.',
defaultValue: false,
);
if (!confirmation) {
exit(ExitCode.success.code);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/src/workflows/ensure_cache.workflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ Future<CacheFlutterVersion> ensureCacheWorkflow(
final shouldInstallConfirmed = logger.confirm(
'Would you like to install it now?',
defaultValue: true,
ciDefaultValue: false,
);

if (!shouldInstallConfirmed) {
Expand Down
5 changes: 4 additions & 1 deletion lib/src/workflows/use_version.workflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ Future<void> useVersionWorkflow({
logger
..spacer
..info('No pubspec.yaml detected in this directory');
final proceed = logger.confirm('Would you like to continue?');
final proceed = logger.confirm(
'Would you like to continue?',
defaultValue: true,
);

if (!proceed) exit(ExitCode.success.code);
}
Expand Down

0 comments on commit 7d50e8e

Please sign in to comment.