final protected function parseOptions()

in src/shipit/phase/ShipItPhaseRunner.php [141:204]


  final protected function parseOptions(
    vec<ShipItCLIArgument> $config,
    dict<string, mixed> $raw_opts,
  ): void {
    foreach ($config as $opt) {
      $is_optional = Str\slice($opt['long_name'], -2) === '::';
      $is_required = !$is_optional && Str\slice($opt['long_name'], -1) === ':';
      $is_bool = !$is_optional && !$is_required;
      $short = Str\trim_right(Shapes::idx($opt, 'short_name', ''), ':');
      $long = Str\trim_right($opt['long_name'], ':');

      if (!Str\is_empty($short) && C\contains_key($raw_opts, $short)) {
        $key = '-'.$short;
        $value = $is_bool ? true : $raw_opts[$short];
      } else if (C\contains_key($raw_opts, $long)) {
        $key = '--'.$long;
        $value = $is_bool ? true : $raw_opts[$long];
      } else {
        $key = null;
        $value = $is_bool ? false : '';

        if ($is_required) {
          ShipItLogger::err("ERROR: Expected --%s\n\n", $long);
          self::printHelp($config);
          throw new ShipItExitException(1);
        }
      }

      $handler = Shapes::idx($opt, 'write');
      if ($handler && $value !== '' && $value !== false) {
        $handler((string)$value);
      }

      if ($key === null) {
        continue;
      }

      $description = Shapes::idx($opt, 'description');
      if ($description !== null && $description !== '') {
        continue;
      }

      $replacement = Shapes::idx($opt, 'replacement');
      if ($replacement !== null) {
        ShipItLogger::err(
          "%s %s, use %s instead\n",
          $key,
          $handler ? 'is deprecated' : 'has been removed',
          $replacement,
        );
        if ($handler === null) {
          throw new ShipItExitException(1);
        }
      } else {
        invariant(
          $handler === null,
          "Option '%s' is not a no-op, is undocumented, and doesn't have a ".
          'documented replacement.',
          $key,
        );
        ShipItLogger::err("%s is deprecated and a no-op\n", $key);
      }
    }
  }