1. /**
  2. * Parses command-line arguments for staging environment message queue configuration.
  3. *
  4. * @param {string[]} args An array of command-line arguments.
  5. * @returns {object} An object containing the parsed configuration. Returns an empty object if no valid arguments are provided.
  6. */
  7. function parseStagingQueueArgs(args) {
  8. const config = {};
  9. if (!args || args.length === 0) {
  10. return config; // Return empty object if no arguments provided
  11. }
  12. // Basic argument parsing with checks for presence and type
  13. if (args.length >= 1) {
  14. config.queue_url = args[0]; // Queue URL
  15. }
  16. if (args.length >= 2) {
  17. config.username = args[1]; // Username
  18. }
  19. if (args.length >= 3) {
  20. config.password = args[2]; // Password
  21. }
  22. if (args.length >= 4) {
  23. config.exchange_name = args[3]; // Exchange name
  24. }
  25. if (args.length >= 5) {
  26. config.routing_key = args[4]; // Routing key
  27. }
  28. if (args.length >= 6) {
  29. config.environment = args[5]; // Environment (staging) - for validation
  30. if (config.environment !== "staging") {
  31. console.warn("Environment is not 'staging'. Configuration may not be suitable.");
  32. }
  33. }
  34. if (args.length >= 7) {
  35. config.visibility_timeout = parseInt(args[6], 10); // Visibility Timeout (in seconds)
  36. if (isNaN(config.visibility_timeout)) {
  37. console.warn("Invalid visibility_timeout. Ignoring.");
  38. }
  39. }
  40. return config;
  41. }

Add your comment