CliOptions.parse constructor

CliOptions.parse(
  1. List<String> args
)

Implementation

factory CliOptions.parse(List<String> args) {
  String? projectPath;
  var configPath = 'rebrand_config.json';
  var showHelp = false;
  var showVersion = false;
  var renameOnly = false;
  var labelOnly = false;
  var launcherOnly = false;
  var splashOnly = false;

  for (var i = 0; i < args.length; i++) {
    final arg = args[i];

    if (arg == '-h' || arg == '--help') {
      showHelp = true;
      continue;
    }

    if (arg == '-v' || arg == '--version') {
      showVersion = true;
      continue;
    }

    if (arg == '--rename') {
      renameOnly = true;
      continue;
    }

    if (arg == '--label' || arg == '--app-name') {
      labelOnly = true;
      continue;
    }

    if (arg == '--launcher') {
      launcherOnly = true;
      continue;
    }

    if (arg == '--splash') {
      splashOnly = true;
      continue;
    }

    if (arg == '-p' || arg == '--project') {
      if (i + 1 >= args.length) {
        throw const CliArgumentException('Missing value for --project.');
      }
      projectPath = _assignProjectPath(projectPath, args[++i]);
      continue;
    }

    if (arg.startsWith('--project=')) {
      final value = arg.substring('--project='.length);
      if (value.isEmpty) {
        throw const CliArgumentException('Missing value for --project.');
      }
      projectPath = _assignProjectPath(projectPath, value);
      continue;
    }

    if (arg == '-c' || arg == '--config') {
      if (i + 1 >= args.length) {
        throw const CliArgumentException('Missing value for --config.');
      }
      configPath = args[++i];
      continue;
    }

    if (arg.startsWith('--config=')) {
      final value = arg.substring('--config='.length);
      if (value.isEmpty) {
        throw const CliArgumentException('Missing value for --config.');
      }
      configPath = value;
      continue;
    }

    if (arg.startsWith('-')) {
      throw CliArgumentException(_suggestOption(arg));
    }

    projectPath = _assignProjectPath(projectPath, arg);
  }

  return CliOptions(
    projectPath: projectPath,
    configPath: configPath,
    showHelp: showHelp,
    showVersion: showVersion,
    renameOnly: renameOnly,
    labelOnly: labelOnly,
    launcherOnly: launcherOnly,
    splashOnly: splashOnly,
  );
}