<?php
/**
* Exports command-line options for staging environments with default values.
*
* This script reads command-line arguments and generates a JSON output
* representing the configuration for a staging environment. Defaults are
* applied where necessary.
*/
// Define default values for configuration options.
$default_values = [
'environment' => 'staging',
'api_key' => 'staging_api_key',
'database_host' => 'staging.example.com',
'database_name' => 'staging_db',
'log_level' => 'info',
'debug_mode' => false,
'timeout_seconds' => 30,
];
// Read command-line arguments.
$args = getopt("a:b:c:d:l:t:", ["api_key", "database_host", "database_name", "log_level", "timeout"]);
// Merge command-line arguments with default values.
$config = array_merge($default_values, $args);
// Validate configuration (optional - add more checks as needed).
if (empty($config['api_key'])) {
echo "Error: API key is required.\n";
exit(1);
}
// Output the configuration as JSON.
header('Content-Type: application/json');
echo json_encode($config, JSON_PRETTY_PRINT);
?>
Add your comment