run method

Future<int> run(
  1. List<String> arguments
)

Executes the CLI with raw arguments. Returns exit code integer.

Implementation

Future<int> run(List<String> arguments) async {
  try {
    if (arguments.isEmpty) {
      return await _commands['help']!.execute(arguments);
    }

    final options = _parser.parse(arguments);

    if (options.showVersion) {
      return await _commands['version']!.execute(options.commandArgs);
    }

    if (options.showHelp || options.commandName == null) {
      return await _commands['help']!.execute(options.commandArgs);
    }

    final cmdName = options.commandName!;
    final command = _commands[cmdName];

    if (command == null) {
      _output
          .error('Unknown command: $cmdName\n\nRun:\n  flutter_setup --help');
      return 64; // Usage error exit code
    }

    return await command.execute(options.commandArgs);
  } on CliException catch (e) {
    _output.error(e.message);
    return e.exitCode;
  } on FileSystemException catch (e) {
    final pathInfo = e.path != null ? ' at "${e.path}"' : '';
    _output.error('FileSystem Error: ${e.message}$pathInfo');
    return 73; // IO error exit code
  } catch (e, st) {
    _output.error('An unexpected error occurred: $e\n$st');
    return 1;
  }
}