process method

Future<void> process()

The process method is used to process the arguments and call the controllers. Call this function to start the application.

Implementation

Future<void> process() async {
  if (args.isEmpty) {
    main.init(manager: this);
    var res = await main.run(main);
    res.log();
    return;
  }

  try {
    for (var controller in controllers) {
      controller.init(manager: this);

      if (controller.name == args[0]) {
        for (var option in controller.options) {
          final find = _findOptionValue(args, option);
          option.value = find.value;
          option.existsInArgs = find.exist;
        }

        var res = await controller.run(controller);
        res.log();
        return;
      }
    }

    main.init(manager: this);
    for (var option in main.options) {
      final find = _findOptionValue(args, option);
      option.value = find.value;
      option.existsInArgs = find.exist;
    }

    var res = await main.run(main);
    res.log();
    return;
  } catch (e) {
    CappConsole.write("Error: ${e.toString()}", CappColors.error);
  }
  CappConsole.write(getHelp(), CappColors.warning);
}