main.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env node
  2. const commandLineUsage = require('command-line-usage');
  3. const log4js = require('log4js');
  4. const path = require('path');
  5. const logger = log4js.getLogger();
  6. logger.level = 'info';
  7. const sections = [
  8. {
  9. header: 'CQHTTP Twitter Bot',
  10. content: 'The QQ Bot that forwards twitters.'
  11. },
  12. {
  13. header: 'Synopsis',
  14. content: [
  15. '$ cqhttp-twitter-bot {underline config.json}',
  16. '$ cqhttp-twitter-bot {bold --help}'
  17. ]
  18. },
  19. {
  20. header: 'Documentation',
  21. content: [
  22. 'Project home: {underline https://github.com/rikakomoe/cqhttp-twitter-bot}',
  23. 'Example config: {underline https://qwqq.pw/b96yt}'
  24. ]
  25. }
  26. ];
  27. const usage = commandLineUsage(sections);
  28. const args = process.argv.slice(2);
  29. if (args.length === 0 || args[0] === 'help' || args[0] === '-h' || args[0] === '--help') {
  30. console.log(usage);
  31. process.exit(0);
  32. }
  33. const configPath = args[0];
  34. let config;
  35. try {
  36. config = require(path.resolve(configPath));
  37. }
  38. catch (e) {
  39. console.log("Failed to parse config file: ", configPath);
  40. console.log(usage);
  41. process.exit(1);
  42. }
  43. console.log(config);