list_tracking.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var ArgumentParser, Base, Command, E, PackageJson, User, add_option_dict, env, format_fingerprint, iced, log, make_esc, 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. exports.Command = Command = (function(_super) {
  22. __extends(Command, _super);
  23. function Command() {
  24. return Command.__super__.constructor.apply(this, arguments);
  25. }
  26. Command.prototype.OPTS = {
  27. v: {
  28. alias: 'verbose',
  29. action: 'storeTrue',
  30. help: 'a full dump, with more gory details'
  31. },
  32. j: {
  33. alias: 'json',
  34. action: 'storeTrue',
  35. help: 'output in json format; default is simple text list'
  36. }
  37. };
  38. Command.prototype.use_session = function() {
  39. return true;
  40. };
  41. Command.prototype.needs_configuration = function() {
  42. return true;
  43. };
  44. Command.prototype.add_subcommand_parser = function(scp) {
  45. var name, opts, sub;
  46. opts = {
  47. help: "list people you are tracking",
  48. aliases: []
  49. };
  50. name = "list-tracking";
  51. sub = scp.addParser(name, opts);
  52. sub.addArgument(["filter"], {
  53. nargs: '?',
  54. help: "a regex to filter by"
  55. });
  56. add_option_dict(sub, this.OPTS);
  57. return [name].concat(opts.aliases);
  58. };
  59. Command.prototype.sort_list = function(v) {
  60. var k, out, pj, sort_fn, val, _i, _len, _ref;
  61. sort_fn = function(a, b) {
  62. a = ("" + a).toLowerCase();
  63. b = ("" + b).toLowerCase();
  64. if (a < b) {
  65. return -1;
  66. } else if (a > b) {
  67. return 1;
  68. } else {
  69. return 0;
  70. }
  71. };
  72. if (v == null) {
  73. return {};
  74. } else {
  75. v = (function() {
  76. var _i, _len, _results;
  77. _results = [];
  78. for (_i = 0, _len = v.length; _i < _len; _i++) {
  79. pj = v[_i];
  80. _results.push([pj.body.track.basics.username, pj]);
  81. }
  82. return _results;
  83. })();
  84. v.sort(sort_fn);
  85. out = {};
  86. for (_i = 0, _len = v.length; _i < _len; _i++) {
  87. _ref = v[_i], k = _ref[0], val = _ref[1];
  88. out[k] = val;
  89. }
  90. return out;
  91. }
  92. };
  93. Command.prototype.condense_record = function(o) {
  94. var out, proofs, rp, rps, v, _ref;
  95. if ((rps = o.body.track.remote_proofs) == null) {
  96. rps = [];
  97. }
  98. proofs = (function() {
  99. var _i, _len, _ref, _results;
  100. _results = [];
  101. for (_i = 0, _len = rps.length; _i < _len; _i++) {
  102. rp = rps[_i];
  103. if ((v = rp != null ? (_ref = rp.remote_key_proof) != null ? _ref.check_data_json : void 0 : void 0)) {
  104. _results.push(v);
  105. }
  106. }
  107. return _results;
  108. })();
  109. out = {
  110. uid: o.body.track.id,
  111. key: (_ref = o.body.track.key.key_fingerprint) != null ? _ref.toUpperCase() : void 0,
  112. proofs: proofs,
  113. ctime: o.ctime
  114. };
  115. return out;
  116. };
  117. Command.prototype.condense_records = function(d) {
  118. var k, out, v;
  119. out = {};
  120. for (k in d) {
  121. v = d[k];
  122. out[k] = this.condense_record(v);
  123. }
  124. return out;
  125. };
  126. Command.prototype.display_json = function(d) {
  127. if (!this.argv.verbose) {
  128. d = this.condense_records(d);
  129. }
  130. return JSON.stringify(d, null, " ");
  131. };
  132. Command.prototype.display = function(v) {
  133. if (this.argv.json) {
  134. return this.display_json(v);
  135. } else {
  136. return this.display_text(v);
  137. }
  138. };
  139. Command.prototype.display_text_line = function(k, v) {
  140. var fields, p, proofs, _i, _len, _ref;
  141. fields = [k];
  142. if (this.argv.verbose) {
  143. fields.push(v.key, v.ctime);
  144. proofs = [];
  145. _ref = v.proofs;
  146. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  147. p = _ref[_i];
  148. if ((p.name != null) && (p.username != null)) {
  149. proofs.push("" + p.name + ":" + p.username);
  150. }
  151. }
  152. proofs.sort();
  153. fields = fields.concat(proofs);
  154. }
  155. return fields.join("\t");
  156. };
  157. Command.prototype.display_text = function(d) {
  158. var k, lines, v;
  159. d = this.condense_records(d);
  160. lines = (function() {
  161. var _results;
  162. _results = [];
  163. for (k in d) {
  164. v = d[k];
  165. _results.push(this.display_text_line(k, v));
  166. }
  167. return _results;
  168. }).call(this);
  169. return lines.join("\n");
  170. };
  171. Command.prototype.filter_list = function(d) {
  172. var cd, k, out, proof, rps, v, _i, _len, _ref, _ref1, _ref2, _ref3, _ref4;
  173. if (this.filter_rxx != null) {
  174. out = {};
  175. for (k in d) {
  176. v = d[k];
  177. if (k.match(this.filter_rxx)) {
  178. out[k] = v;
  179. } else if ((rps = (_ref = v.body) != null ? (_ref1 = _ref.track) != null ? _ref1.remote_proofs : void 0 : void 0) != null) {
  180. for (_i = 0, _len = rps.length; _i < _len; _i++) {
  181. proof = rps[_i];
  182. if ((cd = proof != null ? (_ref2 = proof.remote_key_proof) != null ? _ref2.check_data_json : void 0 : void 0) != null) {
  183. if (((_ref3 = cd.username) != null ? _ref3.match(this.filter_rxx) : void 0) || ((_ref4 = cd.hostname) != null ? _ref4.match(this.filter_rxx) : void 0)) {
  184. out[k] = v;
  185. break;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. d = out;
  192. }
  193. return d;
  194. };
  195. Command.prototype.parse_filter = function(cb) {
  196. var e, err, f;
  197. err = null;
  198. if (((f = this.argv.filter) != null) && f.length) {
  199. try {
  200. this.filter_rxx = new RegExp(f, "i");
  201. } catch (_error) {
  202. e = _error;
  203. err = new E.ArgsError("Bad regex specified: " + e.message);
  204. }
  205. }
  206. return cb(err);
  207. };
  208. Command.prototype.run = function(cb) {
  209. var esc, list, logged_in, me, un, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  210. __iced_k = __iced_k_noop;
  211. ___iced_passed_deferral = iced.findDeferral(arguments);
  212. esc = make_esc(cb, "Command::run");
  213. (function(_this) {
  214. return (function(__iced_k) {
  215. __iced_deferrals = new iced.Deferrals(__iced_k, {
  216. parent: ___iced_passed_deferral,
  217. filename: "/Users/max/src/keybase/node-client/src/command/list_tracking.iced",
  218. funcname: "Command.run"
  219. });
  220. _this.parse_filter(esc(__iced_deferrals.defer({
  221. lineno: 153
  222. })));
  223. __iced_deferrals._fulfill();
  224. });
  225. })(this)((function(_this) {
  226. return function() {
  227. (function(__iced_k) {
  228. if ((un = env().get_username()) != null) {
  229. (function(__iced_k) {
  230. __iced_deferrals = new iced.Deferrals(__iced_k, {
  231. parent: ___iced_passed_deferral,
  232. filename: "/Users/max/src/keybase/node-client/src/command/list_tracking.iced",
  233. funcname: "Command.run"
  234. });
  235. session.check(esc(__iced_deferrals.defer({
  236. assign_fn: (function() {
  237. return function() {
  238. return logged_in = arguments[0];
  239. };
  240. })(),
  241. lineno: 156
  242. })));
  243. __iced_deferrals._fulfill();
  244. })(function() {
  245. (function(__iced_k) {
  246. __iced_deferrals = new iced.Deferrals(__iced_k, {
  247. parent: ___iced_passed_deferral,
  248. filename: "/Users/max/src/keybase/node-client/src/command/list_tracking.iced",
  249. funcname: "Command.run"
  250. });
  251. User.load_me({
  252. secret: false
  253. }, esc(__iced_deferrals.defer({
  254. assign_fn: (function() {
  255. return function() {
  256. return me = arguments[0];
  257. };
  258. })(),
  259. lineno: 157
  260. })));
  261. __iced_deferrals._fulfill();
  262. })(function() {
  263. list = _this.sort_list(me.list_trackees());
  264. list = _this.filter_list(list);
  265. return __iced_k(log.console.log(_this.display(list)));
  266. });
  267. });
  268. } else {
  269. return __iced_k(log.warn("Not logged in"));
  270. }
  271. })(function() {
  272. return cb(null);
  273. });
  274. };
  275. })(this));
  276. };
  277. return Command;
  278. })(Base);
  279. }).call(this);