runCLI function

void runCLI(
  1. List<String> args
)

Entry point for the sg command. Reads sg_cli.yaml to work out which architecture version the project uses (Max, Bronze, or Amber) and hands the raw command-line args over to that version's command runner.

Implementation

void runCLI(List<String> args) {
  arguments = args;
  SgConfig? config = getConfig();
  if (config == null) {
    final isInitCmd = args.length == 1 && args.first == 'init';
    final isHelpCmd = args.length == 1 && (args.first == 'help' || args.first == '--help' || args.first == '-help' || args.first == '-h' || args.first == 'h');

    if (isInitCmd || isHelpCmd || args.isEmpty) {
      config = SgConfig(version: kMax, routePaths: []);
    } else {
      ConsoleLogger.error('Invalid config file sg_cli.yaml');
      return;
    }
  } else if (args.isEmpty) {
    Max.runCommand();
    return;
  }
  sgConfig = config;

  final cliVersions = {
    kAmber: Amber.runCommand,
    kBronze: Bronze.runCommand,
    kMax: Max.runCommand,
  };

  final command = cliVersions[config.version];

  command?.call();
  if (command == null) ConsoleLogger.error('Invalid config file sg_cli.yaml');
}