1. #!/usr/bin/env node
  2. const fs = require('fs');
  3. const path = require('path');
  4. const { program } = require('commander');
  5. // Define default configuration file path
  6. const defaultConfigPath = path.resolve('./config.json');
  7. // Function to load configuration from file
  8. function loadConfig(filePath) {
  9. try {
  10. const configData = fs.readFileSync(filePath, 'utf8');
  11. return JSON.parse(configData);
  12. } catch (error) {
  13. console.error(`Error loading configuration from ${filePath}: ${error.message}`);
  14. return {}; // Return empty object on error
  15. }
  16. }
  17. // Load configuration
  18. const config = loadConfig(defaultConfigPath);
  19. // Define command-line options
  20. program
  21. .option('-o, --output <path>', 'Output file path')
  22. .option('-n, --number <number>', 'Number of runs', Number)
  23. .option('-t, --threshold <number>', 'Threshold value', Number);
  24. program.parse(process.argv);
  25. const options = program.opts();
  26. // Merge command-line options with configuration values
  27. const mergedConfig = { ...config, ...options };
  28. // Use mergedConfig for scheduled runs
  29. console.log('Using the following configuration:');
  30. console.log(JSON.stringify(mergedConfig, null, 2));
  31. //Example Usage - Replace with your actual scheduled run logic
  32. if(mergedConfig.number){
  33. console.log(`Running ${mergedConfig.number} times...`);
  34. }

Add your comment