cli.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import * as fs from 'fs'
  2. import { app } from 'electron'
  3. export function parseArgs (argv, cwd) {
  4. if (argv[0].includes('node')) {
  5. argv = argv.slice(1)
  6. }
  7. return require('yargs')
  8. .usage('terminus [command] [arguments]')
  9. .command('open [directory]', 'open a shell in a directory', {
  10. directory: { type: 'string', 'default': cwd },
  11. })
  12. .command('run [command...]', 'run a command in the terminal', {
  13. command: { type: 'string' },
  14. })
  15. .command('paste [text]', 'paste stdin into the active tab', yargs => {
  16. return yargs.option('escape', {
  17. alias: 'e',
  18. type: 'boolean',
  19. describe: 'Perform shell escaping'
  20. }).positional('text', {
  21. type: 'string'
  22. })
  23. })
  24. .version('version', '', app.getVersion())
  25. .option('debug', {
  26. alias: 'd',
  27. describe: 'Show DevTools on start',
  28. type: 'boolean'
  29. })
  30. .option('version', {
  31. alias: 'v',
  32. describe: 'Show version and exit',
  33. type: 'boolean'
  34. })
  35. .help('help')
  36. .strict()
  37. .parse(argv.slice(1))
  38. }