1. <?php
  2. /**
  3. * Exports command-line options for staging environments with default values.
  4. *
  5. * This script reads command-line arguments and generates a JSON output
  6. * representing the configuration for a staging environment. Defaults are
  7. * applied where necessary.
  8. */
  9. // Define default values for configuration options.
  10. $default_values = [
  11. 'environment' => 'staging',
  12. 'api_key' => 'staging_api_key',
  13. 'database_host' => 'staging.example.com',
  14. 'database_name' => 'staging_db',
  15. 'log_level' => 'info',
  16. 'debug_mode' => false,
  17. 'timeout_seconds' => 30,
  18. ];
  19. // Read command-line arguments.
  20. $args = getopt("a:b:c:d:l:t:", ["api_key", "database_host", "database_name", "log_level", "timeout"]);
  21. // Merge command-line arguments with default values.
  22. $config = array_merge($default_values, $args);
  23. // Validate configuration (optional - add more checks as needed).
  24. if (empty($config['api_key'])) {
  25. echo "Error: API key is required.\n";
  26. exit(1);
  27. }
  28. // Output the configuration as JSON.
  29. header('Content-Type: application/json');
  30. echo json_encode($config, JSON_PRETTY_PRINT);
  31. ?>

Add your comment