cmd.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use strict';
  2. const yargs = require('yargs');
  3. const argv = yargs(process.argv.slice(1))
  4. .usage('Usage: $0 [file] [options]')
  5. .help('help')
  6. .alias('version', 'v')
  7. .option('help', {
  8. alias: 'h'
  9. })
  10. .option('development', {
  11. alias: 'd',
  12. type: 'boolean',
  13. describe: 'Enable Debug Mode',
  14. })
  15. .option('classic', {
  16. alias: 'c',
  17. type: 'boolean',
  18. describe: 'Use classic window title bar (for Windows only)',
  19. })
  20. .option('minimal', {
  21. alias: 'm',
  22. type: 'boolean',
  23. describe: 'Hide the main window at startup',
  24. })
  25. .command({
  26. command: '$0 [file]',
  27. aliases: ['new'],
  28. desc: 'Create new download task from exist torrent/metalink file'
  29. })
  30. .argv;
  31. function parseArguments(argv) {
  32. if (!argv || argv.length < 2) {
  33. return undefined;
  34. }
  35. const actualArgv = [];
  36. for (let i = 1; i < argv.length; i++) {
  37. if (argv[i][0] !== '-' || argv[i] === '-d' || argv[i] === '--development') {
  38. actualArgv.push(argv[i]);
  39. }
  40. }
  41. try {
  42. return yargs(actualArgv)
  43. .command({
  44. command: '$0 [file] [options]'
  45. })
  46. .option('development', {
  47. alias: 'd',
  48. type: 'boolean'
  49. })
  50. .argv;
  51. } catch (ex) {
  52. return undefined;
  53. }
  54. }
  55. module.exports = {
  56. argv: argv,
  57. parseArguments: parseArguments
  58. };