'inspect']; } if ($action !== 'apply') { throw new \InvalidArgumentException( '用法:php xcat cloudTrafficSettlementRecovery inspect;' . '或 apply --plan-hash=<64位哈希> --apply' ); } $options = []; foreach (array_slice($argv, 3) as $argument) { if ($argument === '--apply') { if (isset($options['apply'])) { throw new \InvalidArgumentException('参数重复:apply'); } $options['apply'] = true; continue; } if (preg_match('/^--([a-z-]+)=(.*)$/D', $argument, $match) !== 1 || isset($options[$match[1]])) { throw new \InvalidArgumentException('恢复参数无效或重复'); } $options[$match[1]] = $match[2]; } if (array_diff(array_keys($options), ['plan-hash', 'apply']) !== [] || ($options['apply'] ?? false) !== true || preg_match('/^[a-f0-9]{64}$/D', (string) ($options['plan-hash'] ?? '')) !== 1) { throw new \InvalidArgumentException( '执行恢复必须绑定 inspect 返回的 plan-hash 并显式提供 --apply' ); } return [ 'action' => 'apply', 'plan_hash' => (string) $options['plan-hash'], ]; } }