execute method

Future<void> execute(
  1. List<String> args
)

Starts the initialization wizard or loads from a file if the '--from' flag is provided.

Implementation

Future<void> execute(List<String> args) async {
  if (!ConfigService.isValidProject(_log)) return;

  final parser = ArgParser()
    ..addOption(
      'from',
      help: 'Path to a JSON config file to initialize without prompts.',
    );

  try {
    final results = parser.parse(args);

    if (results.wasParsed('from')) {
      final filePath = results['from'] as String;
      await InitFromFile(logger: _log).execute(filePath);
    } else {
      await InitWizard(logger: _log).execute();
    }
  } on FormatException catch (e) {
    _log.error('❌ Error parsing arguments: ${e.message}');
  } catch (e) {
    if (e is CliException && e.isLogged) {
      // Already reported, just exit gracefully
      return;
    }
    final msg = e is CliException ? '$e' : 'Unexpected error: $e';
    _log.error('❌ $msg');
  }
}