util.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.exit = exports.passedTime = exports.formatTime = exports.printStatus = exports.parseArgs = void 0;
  4. var moment = require("moment");
  5. exports.parseArgs = function (args) {
  6. var inArgs = function (term) {
  7. return args.find(function (a) { return a.search(term) > -1; }) ? true : false;
  8. };
  9. var options = {
  10. verbose: inArgs("--verbose") ? 2 : inArgs("--quiet") ? 0 : 1,
  11. channel: inArgs("--channel"),
  12. council: inArgs("--council"),
  13. forum: inArgs("--forum"),
  14. proposals: inArgs("--proposals")
  15. };
  16. if (options.verbose > 1)
  17. console.debug("args", args, "\noptions", options);
  18. return options;
  19. };
  20. exports.printStatus = function (opts, data) {
  21. if (opts.verbose < 1)
  22. return;
  23. var block = data.block, chain = data.chain, proposals = data.proposals, cats = data.cats, posts = data.posts, threads = data.threads;
  24. var date = exports.formatTime();
  25. var message = "[" + date + "] Chain:" + chain + " Block:" + block + " ";
  26. if (opts.forum)
  27. message += "Post:" + posts[1] + " Cat:" + cats[1] + " Thread:" + threads[1] + " ";
  28. if (opts.proposals)
  29. message += "Proposals:" + proposals.current + " (Active:" + proposals.active.length + " Pending:" + proposals.executing.length + ") ";
  30. console.log(message);
  31. };
  32. // time
  33. exports.formatTime = function (time) {
  34. return moment(time).format("H:mm:ss");
  35. };
  36. exports.passedTime = function (start, now) {
  37. return exports.formatTime(moment.utc(moment(now).diff(moment(start))));
  38. };
  39. exports.exit = function (log) {
  40. log("\nNo connection, exiting.\n");
  41. process.exit();
  42. };