search.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var ArgumentParser, Base, Command, E, PackageJson, SERVICES, User, add_option_dict, env, format_fingerprint, iced, log, make_esc, req, session, util, __iced_k, __iced_k_noop,
  4. __hasProp = {}.hasOwnProperty,
  5. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  6. iced = require('iced-runtime').iced;
  7. __iced_k = __iced_k_noop = function() {};
  8. Base = require('./base').Base;
  9. log = require('../log');
  10. ArgumentParser = require('argparse').ArgumentParser;
  11. add_option_dict = require('./argparse').add_option_dict;
  12. PackageJson = require('../package').PackageJson;
  13. session = require('../session').session;
  14. make_esc = require('iced-error').make_esc;
  15. env = require('../env').env;
  16. log = require('../log');
  17. User = require('../user').User;
  18. format_fingerprint = require('pgp-utils').util.format_fingerprint;
  19. util = require('util');
  20. E = require('../err').E;
  21. req = require('../req');
  22. SERVICES = ["github", "twitter", "reddit", "hackernews"];
  23. exports.Command = Command = (function(_super) {
  24. __extends(Command, _super);
  25. function Command() {
  26. return Command.__super__.constructor.apply(this, arguments);
  27. }
  28. Command.prototype.OPTS = {
  29. v: {
  30. alias: 'verbose',
  31. action: 'storeTrue',
  32. help: 'a full dump, with more gory details'
  33. },
  34. j: {
  35. alias: 'json',
  36. action: 'storeTrue',
  37. help: 'output in json format; default is simple text list'
  38. }
  39. };
  40. Command.prototype.use_session = function() {
  41. return true;
  42. };
  43. Command.prototype.needs_configuration = function() {
  44. return false;
  45. };
  46. Command.prototype.add_subcommand_parser = function(scp) {
  47. var name, opts, sub;
  48. opts = {
  49. help: "search all users",
  50. aliases: []
  51. };
  52. name = "search";
  53. sub = scp.addParser(name, opts);
  54. sub.addArgument(["query"], {
  55. nargs: 1,
  56. help: "a substring to find"
  57. });
  58. add_option_dict(sub, this.OPTS);
  59. return [name].concat(opts.aliases);
  60. };
  61. Command.prototype.search = function(cb) {
  62. var args, body, err, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  63. __iced_k = __iced_k_noop;
  64. ___iced_passed_deferral = iced.findDeferral(arguments);
  65. args = {
  66. endpoint: "user/autocomplete",
  67. args: {
  68. q: this.argv.query[0]
  69. }
  70. };
  71. (function(_this) {
  72. return (function(__iced_k) {
  73. __iced_deferrals = new iced.Deferrals(__iced_k, {
  74. parent: ___iced_passed_deferral,
  75. filename: "/home/max/src/keybase/node-client/src/command/search.iced",
  76. funcname: "Command.search"
  77. });
  78. req.get(args, __iced_deferrals.defer({
  79. assign_fn: (function() {
  80. return function() {
  81. err = arguments[0];
  82. return body = arguments[1];
  83. };
  84. })(),
  85. lineno: 59
  86. }));
  87. __iced_deferrals._fulfill();
  88. });
  89. })(this)((function(_this) {
  90. return function() {
  91. return cb(err, body);
  92. };
  93. })(this));
  94. };
  95. Command.prototype.reformat_results = function(list) {
  96. var c, entry, n, obj, ret, svc, v, _i, _j, _len, _len1, _ref, _ref1;
  97. ret = [];
  98. for (_i = 0, _len = list.length; _i < _len; _i++) {
  99. entry = list[_i];
  100. if (!((c = entry.components) != null)) {
  101. continue;
  102. }
  103. obj = {
  104. username: c.username.val,
  105. key: (_ref = c.key_fingerprint) != null ? _ref.val.replace(/\s+/g, "") : void 0
  106. };
  107. for (_j = 0, _len1 = SERVICES.length; _j < _len1; _j++) {
  108. svc = SERVICES[_j];
  109. if ((n = c[svc]) != null) {
  110. obj[svc] = n.val;
  111. }
  112. }
  113. if ((_ref1 = c.websites) != null ? _ref1.length : void 0) {
  114. obj.websites = (function() {
  115. var _k, _len2, _ref2, _results;
  116. _ref2 = c.websites;
  117. _results = [];
  118. for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
  119. v = _ref2[_k];
  120. _results.push("" + v.protocol + "//" + v.val);
  121. }
  122. return _results;
  123. })();
  124. }
  125. obj.score = entry.total_score;
  126. if (this.logged_in) {
  127. obj.is_followee = entry.is_followee;
  128. }
  129. ret.push(obj);
  130. }
  131. return ret;
  132. };
  133. Command.prototype.display = function(v) {
  134. if (this.argv.json) {
  135. return this.display_json(v);
  136. } else {
  137. return this.display_text(v);
  138. }
  139. };
  140. Command.prototype.display_text = function(v) {
  141. var fields, line, lines, n, rec, svc, tmp, _i, _j, _len, _len1;
  142. lines = [];
  143. for (_i = 0, _len = v.length; _i < _len; _i++) {
  144. rec = v[_i];
  145. fields = [];
  146. if (this.logged_in) {
  147. fields.push(rec.is_followee ? '*' : '-');
  148. }
  149. fields.push(rec.username, rec.key);
  150. for (_j = 0, _len1 = SERVICES.length; _j < _len1; _j++) {
  151. svc = SERVICES[_j];
  152. if ((n = rec[svc])) {
  153. fields.push("" + svc + ":" + n);
  154. }
  155. }
  156. if ((tmp = rec.websites) != null) {
  157. fields = fields.concat(tmp);
  158. }
  159. line = fields.join("\t");
  160. lines.push(line);
  161. }
  162. return lines.join("\n");
  163. };
  164. Command.prototype.display_json = function(v) {
  165. return JSON.stringify(v, null, " ");
  166. };
  167. Command.prototype.run = function(cb) {
  168. var d, esc, list, v, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  169. __iced_k = __iced_k_noop;
  170. ___iced_passed_deferral = iced.findDeferral(arguments);
  171. esc = make_esc(cb, "Command::run");
  172. (function(_this) {
  173. return (function(__iced_k) {
  174. __iced_deferrals = new iced.Deferrals(__iced_k, {
  175. parent: ___iced_passed_deferral,
  176. filename: "/home/max/src/keybase/node-client/src/command/search.iced",
  177. funcname: "Command.run"
  178. });
  179. _this.search(esc(__iced_deferrals.defer({
  180. assign_fn: (function() {
  181. return function() {
  182. return list = arguments[0];
  183. };
  184. })(),
  185. lineno: 113
  186. })));
  187. __iced_deferrals._fulfill();
  188. });
  189. })(this)((function(_this) {
  190. return function() {
  191. (function(__iced_k) {
  192. if ((v = typeof list !== "undefined" && list !== null ? list.completions : void 0) && v.length) {
  193. (function(__iced_k) {
  194. __iced_deferrals = new iced.Deferrals(__iced_k, {
  195. parent: ___iced_passed_deferral,
  196. filename: "/home/max/src/keybase/node-client/src/command/search.iced",
  197. funcname: "Command.run"
  198. });
  199. session.load_and_check(esc(__iced_deferrals.defer({
  200. assign_fn: (function(__slot_1) {
  201. return function() {
  202. return __slot_1.logged_in = arguments[0];
  203. };
  204. })(_this),
  205. lineno: 115
  206. })));
  207. __iced_deferrals._fulfill();
  208. })(function() {
  209. return __iced_k(v = _this.reformat_results(v));
  210. });
  211. } else {
  212. return __iced_k(v = []);
  213. }
  214. })(function() {
  215. if ((d = _this.display(v)).length) {
  216. log.console.log(d);
  217. }
  218. return cb(null, (v.length === 0 ? 1 : 0));
  219. });
  220. };
  221. })(this));
  222. };
  223. return Command;
  224. })(Base);
  225. }).call(this);