/**
* Parses command-line arguments for staging environment message queue configuration.
*
* @param {string[]} args An array of command-line arguments.
* @returns {object} An object containing the parsed configuration. Returns an empty object if no valid arguments are provided.
*/
function parseStagingQueueArgs(args) {
const config = {};
if (!args || args.length === 0) {
return config; // Return empty object if no arguments provided
}
// Basic argument parsing with checks for presence and type
if (args.length >= 1) {
config.queue_url = args[0]; // Queue URL
}
if (args.length >= 2) {
config.username = args[1]; // Username
}
if (args.length >= 3) {
config.password = args[2]; // Password
}
if (args.length >= 4) {
config.exchange_name = args[3]; // Exchange name
}
if (args.length >= 5) {
config.routing_key = args[4]; // Routing key
}
if (args.length >= 6) {
config.environment = args[5]; // Environment (staging) - for validation
if (config.environment !== "staging") {
console.warn("Environment is not 'staging'. Configuration may not be suitable.");
}
}
if (args.length >= 7) {
config.visibility_timeout = parseInt(args[6], 10); // Visibility Timeout (in seconds)
if (isNaN(config.visibility_timeout)) {
console.warn("Invalid visibility_timeout. Ignoring.");
}
}
return config;
}
Add your comment