cmd.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 Development Mode (press F12 to open DevTools)',
  14. })
  15. .option('classic', {
  16. alias: 'c',
  17. type: 'boolean',
  18. describe: 'Use classic window title bar (for Windows only)',
  19. })
  20. .command({
  21. command: '$0 [file]',
  22. aliases: ['new'],
  23. desc: 'Create new download task from exist torrent/metalink file'
  24. })
  25. .argv;
  26. function parseFilePath(argv) {
  27. if (!argv || argv.length < 2) {
  28. return undefined;
  29. }
  30. const actualArgv = [];
  31. for (let i = 1; i < argv.length; i++) {
  32. if (argv[i][0] !== '-') {
  33. actualArgv.push(argv[i]);
  34. }
  35. }
  36. const ret = yargs(actualArgv)
  37. .command({
  38. command: '$0 <file>'
  39. })
  40. .argv;
  41. return ret ? ret.file : undefined;
  42. }
  43. module.exports = {
  44. argv: argv,
  45. parseFilePath: parseFilePath
  46. };