cli.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. "use strict";
  2. var _yargs = _interopRequireDefault(require("yargs"));
  3. var _api = require("./api");
  4. var _formatters = require("./formatters");
  5. var _utils = require("./utils");
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  7. const androidPriorityOptions = {
  8. unknown: {
  9. alias: ['U', 'u'],
  10. boolean: true,
  11. default: false,
  12. describe: 'Unknown priority'
  13. },
  14. verbose: {
  15. alias: ['V', 'v'],
  16. boolean: true,
  17. default: false,
  18. describe: 'Verbose priority'
  19. },
  20. debug: {
  21. alias: ['D', 'd'],
  22. boolean: true,
  23. default: false,
  24. describe: 'Debug priority'
  25. },
  26. info: {
  27. alias: ['I', 'i'],
  28. boolean: true,
  29. default: false,
  30. describe: 'Info priority'
  31. },
  32. warn: {
  33. alias: ['W', 'w'],
  34. boolean: true,
  35. default: false,
  36. describe: 'Warn priority'
  37. },
  38. error: {
  39. alias: ['E', 'e'],
  40. boolean: true,
  41. default: false,
  42. describe: 'Error priority'
  43. },
  44. fatal: {
  45. alias: ['F', 'f'],
  46. boolean: true,
  47. default: false,
  48. describe: 'Fatal priority'
  49. },
  50. silent: {
  51. alias: ['S', 's'],
  52. boolean: true,
  53. default: false,
  54. describe: 'Silent priority'
  55. }
  56. };
  57. const iosPriorityOptions = {
  58. debug: {
  59. alias: ['D', 'd'],
  60. boolean: true,
  61. default: false,
  62. describe: 'Debug level'
  63. },
  64. info: {
  65. alias: ['I', 'i'],
  66. boolean: true,
  67. default: false,
  68. describe: 'Info level'
  69. },
  70. error: {
  71. alias: ['E', 'e'],
  72. boolean: true,
  73. default: false,
  74. describe: 'Error level'
  75. }
  76. };
  77. const {
  78. argv: {
  79. _: [platform, filter],
  80. ...args
  81. }
  82. } = _yargs.default.usage('Usage: $0 [options] <platform>').command('android', 'Android', yargs => yargs.command('tag <tags ...>', 'Show logs matching given tags', androidPriorityOptions).command('app <appId>', 'Show logs from application with given identifier', androidPriorityOptions).command('match <regexes...>', 'Show logs matching given patterns', androidPriorityOptions).command('custom <patterns ...>', 'Filter using custom patterns <tag>:<priority>').command('all', 'Show all logs', androidPriorityOptions).demandCommand(1).option('adb-path', {
  83. type: 'string',
  84. describe: 'Use custom path to adb',
  85. nargs: 1
  86. }).example('$0 android tag MyTag', 'Filter logs to only include ones with MyTag tag').example('$0 android tag MyTag -I', 'Filter logs to only include ones with MyTag tag and priority INFO and above').example('$0 android app com.example.myApp', 'Show all logs from com.example.myApp').example('$0 android match device', 'Show all logs matching /device/gm regex').example('$0 android app com.example.myApp -E', 'Show all logs from com.example.myApp with priority ERROR and above').example('$0 android custom *:S MyTag:D', 'Silence all logs and show only ones with MyTag with priority DEBUG and above')).command('ios <filter>', 'iOS', yargs => yargs.command('tag <tags ...>', 'Show logs matching given tags', iosPriorityOptions).command('match <regexes...>', 'Show logs matching given patterns', iosPriorityOptions).command('all', 'Show all logs', iosPriorityOptions).demandCommand(1).example('$0 ios tag MyTag', 'Filter logs to only include ones with MyTag tag').example('$0 ios tag MyTag -i', 'Filter logs to only include ones with MyTag tag and priority Info and Error').example('$0 ios match device', 'Show all logs matching /device/gm regex')).demandCommand(1).help('h').alias('h', 'help').alias('v', 'version').version();
  87. const selectedAndroidPriorities = {
  88. unknown: Boolean(args.unknown),
  89. verbose: Boolean(args.verbose),
  90. debug: Boolean(args.debug),
  91. info: Boolean(args.info),
  92. warn: Boolean(args.warn),
  93. error: Boolean(args.error),
  94. fatal: Boolean(args.fatal),
  95. silent: Boolean(args.silent)
  96. };
  97. const selectedIosPriorities = {
  98. debug: Boolean(args.debug),
  99. info: Boolean(args.info),
  100. error: Boolean(args.error)
  101. };
  102. try {
  103. let createFilter;
  104. switch (filter) {
  105. case 'app':
  106. createFilter = (0, _api.makeAppFilter)(args.appId);
  107. break;
  108. case 'tag':
  109. createFilter = (0, _api.makeTagsFilter)(...args.tags);
  110. break;
  111. case 'match':
  112. createFilter = (0, _api.makeMatchFilter)(...args.regexes.map(value => new RegExp(value, 'gm')));
  113. break;
  114. case 'custom':
  115. createFilter = (0, _api.makeCustomFilter)(...args.patterns);
  116. break;
  117. case 'all':
  118. default:
  119. }
  120. const emitter = (0, _api.logkitty)({
  121. platform: platform,
  122. adbPath: args.adbPath ? String(args.adbPath) : '',
  123. priority: platform === 'android' ? (0, _utils.getMinPriority)(_api.AndroidPriority, selectedAndroidPriorities, _api.AndroidPriority.DEBUG) : (0, _utils.getMinPriority)(_api.IosPriority, selectedIosPriorities, _api.IosPriority.DEFAULT),
  124. filter: createFilter
  125. });
  126. emitter.on('entry', entry => {
  127. process.stdout.write((0, _formatters.formatEntry)(entry));
  128. });
  129. emitter.on('error', error => {
  130. terminate(error);
  131. });
  132. } catch (error) {
  133. terminate(error);
  134. }
  135. function terminate(error) {
  136. // eslint-disable-next-line no-console
  137. console.log((0, _formatters.formatError)(error));
  138. process.exit(1);
  139. }
  140. //# sourceMappingURL=cli.js.map