1. #!/usr/bin/env node
  2. const yargs = require('yargs'); // Minimalistic command-line argument parser
  3. const { hideBin } = require('yargs'); // Hide default yargs options
  4. const argv = yargs(hideBin(process.argv)) // Set up yargs with command-line arguments
  5. .option('mode', {
  6. alias: 'm',
  7. describe: 'Development mode (true/false)',
  8. type: 'boolean',
  9. default: true, // Default to development mode
  10. })
  11. .option('logLevel', {
  12. alias: 'l',
  13. describe: 'Log level (e.g., debug, info, warn, error)',
  14. type: 'string',
  15. default: 'info',
  16. })
  17. .option('apiUrl', {
  18. alias: 'a',
  19. describe: 'API URL to use',
  20. type: 'string',
  21. default: 'http://localhost:3000',
  22. })
  23. .option('port', {
  24. alias: 'p',
  25. describe: 'Port to listen on',
  26. type: 'number',
  27. default: 3000,
  28. })
  29. .help() // Add help command
  30. .alias('help', 'h') // Alias for help command
  31. .argv; // Parse command-line arguments
  32. // Access the options
  33. const { mode, logLevel, apiUrl, port } = argv;
  34. // Example usage: Log the settings
  35. console.log('Development Mode:', mode);
  36. console.log('Log Level:', logLevel);
  37. console.log('API URL:', apiUrl);
  38. console.log('Port:', port);
  39. //Further logic can be added here to use the options.

Add your comment