run method

  1. @override
Future<void> run(
  1. Iterable<String> args
)
override

Parses args and invokes Command.run on the chosen command.

This always returns a Future in case the command is asynchronous. The Future will throw a UsageException if args was invalid.

Implementation

@override
Future<void> run(Iterable<String> args) async {
  // Parse arguments
  final argResults = parse(args);

  // Initialize TUI system with --no-tui flag consideration
  final noTui = argResults['no-tui'] == true;
  initializeTUI(noTui: noTui);

  // Handle --version flag
  if (argResults['version'] == true) {
    final version = _getVersionFromPubspec();
    print('${Constants.toolName} version $version');
    return;
  }

  // Define commands that do not require Clonify settings validation.
  // These commands can run even if the clonify_settings.yaml file is not present or invalid.
  List<String> commandsToSkipValidation = [
    ClonifyCommands.init.name,
    ClonifyCommands.list.name,
  ];

  // Determine if validation should be skipped based on arguments.
  // Validation is skipped for empty arguments (shows help), --help, -h,
  // or specific commands like 'init' and 'list'.
  final shouldSkipValidation =
      args.isEmpty ||
      args.contains('--help') ||
      args.contains('-h') ||
      (args.isNotEmpty && commandsToSkipValidation.contains(args.first));

  if (!shouldSkipValidation) {
    // Validate clonify settings before running any other command.
    // If validation fails, a CustomException is thrown.
    if (!validatedClonifySettings(isSilent: true)) {
      throw CustomException('Validation Failed !');
    }
  }
  // Execute the command using the superclass's run method.
  return super.run(args);
}