index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // @ts-check
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. Object.defineProperty(exports, "help", {
  7. enumerable: true,
  8. get: function() {
  9. return help;
  10. }
  11. });
  12. const _packagejson = /*#__PURE__*/ _interop_require_default(require("../../../package.json"));
  13. function _interop_require_default(obj) {
  14. return obj && obj.__esModule ? obj : {
  15. default: obj
  16. };
  17. }
  18. function help({ message , usage , commands , options }) {
  19. let indent = 2;
  20. // Render header
  21. console.log();
  22. console.log(`${_packagejson.default.name} v${_packagejson.default.version}`);
  23. // Render message
  24. if (message) {
  25. console.log();
  26. for (let msg of message.split("\n")){
  27. console.log(msg);
  28. }
  29. }
  30. // Render usage
  31. if (usage && usage.length > 0) {
  32. console.log();
  33. console.log("Usage:");
  34. for (let example of usage){
  35. console.log(" ".repeat(indent), example);
  36. }
  37. }
  38. // Render commands
  39. if (commands && commands.length > 0) {
  40. console.log();
  41. console.log("Commands:");
  42. for (let command of commands){
  43. console.log(" ".repeat(indent), command);
  44. }
  45. }
  46. // Render options
  47. if (options) {
  48. let groupedOptions = {};
  49. for (let [key, value] of Object.entries(options)){
  50. if (typeof value === "object") {
  51. groupedOptions[key] = {
  52. ...value,
  53. flags: [
  54. key
  55. ]
  56. };
  57. } else {
  58. groupedOptions[value].flags.push(key);
  59. }
  60. }
  61. console.log();
  62. console.log("Options:");
  63. for (let { flags , description , deprecated } of Object.values(groupedOptions)){
  64. if (deprecated) continue;
  65. if (flags.length === 1) {
  66. console.log(" ".repeat(indent + 4 /* 4 = "-i, ".length */ ), flags.slice().reverse().join(", ").padEnd(20, " "), description);
  67. } else {
  68. console.log(" ".repeat(indent), flags.slice().reverse().join(", ").padEnd(24, " "), description);
  69. }
  70. }
  71. }
  72. console.log();
  73. }