prompter.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var Prompter, checkers, iced, log, read, strip, __iced_k, __iced_k_noop;
  4. iced = require('iced-runtime').iced;
  5. __iced_k = __iced_k_noop = function() {};
  6. read = require('read');
  7. checkers = require('./checkers').checkers;
  8. log = require('./log');
  9. exports.Prompter = Prompter = (function() {
  10. function Prompter(_fields) {
  11. this._fields = _fields;
  12. this._data = {};
  13. }
  14. Prompter.prototype.data = function() {
  15. return this._data;
  16. };
  17. Prompter.prototype.clear = function(k) {
  18. return delete this._data[k];
  19. };
  20. Prompter.prototype.run = function(cb) {
  21. var err, k, v, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  22. __iced_k = __iced_k_noop;
  23. ___iced_passed_deferral = iced.findDeferral(arguments);
  24. err = null;
  25. (function(_this) {
  26. return (function(__iced_k) {
  27. var _i, _k, _keys, _ref, _results, _while;
  28. _ref = _this._fields;
  29. _keys = (function() {
  30. var _results1;
  31. _results1 = [];
  32. for (_k in _ref) {
  33. _results1.push(_k);
  34. }
  35. return _results1;
  36. })();
  37. _i = 0;
  38. _results = [];
  39. _while = function(__iced_k) {
  40. var _break, _continue, _next;
  41. _break = function() {
  42. return __iced_k(_results);
  43. };
  44. _continue = function() {
  45. return iced.trampoline(function() {
  46. ++_i;
  47. return _while(__iced_k);
  48. });
  49. };
  50. _next = function(__iced_next_arg) {
  51. _results.push(__iced_next_arg);
  52. return _continue();
  53. };
  54. if (!(_i < _keys.length)) {
  55. return _break();
  56. } else {
  57. k = _keys[_i];
  58. v = _ref[k];
  59. (function(__iced_k) {
  60. __iced_deferrals = new iced.Deferrals(__iced_k, {
  61. parent: ___iced_passed_deferral,
  62. filename: "/Users/max/src/keybase/node-client/src/prompter.iced",
  63. funcname: "Prompter.run"
  64. });
  65. _this.read_field(k, v, __iced_deferrals.defer({
  66. assign_fn: (function() {
  67. return function() {
  68. return err = arguments[0];
  69. };
  70. })(),
  71. lineno: 18
  72. }));
  73. __iced_deferrals._fulfill();
  74. })(function() {
  75. (function(__iced_k) {
  76. if (err != null) {
  77. (function(__iced_k) {
  78. _break()
  79. })(__iced_k);
  80. } else {
  81. return __iced_k();
  82. }
  83. })(_next);
  84. });
  85. }
  86. };
  87. _while(__iced_k);
  88. });
  89. })(this)((function(_this) {
  90. return function() {
  91. return cb(err);
  92. };
  93. })(this));
  94. };
  95. Prompter.prototype.read_field = function(k, _arg, cb) {
  96. var checker, confirm, d, defval, err, first, first_prompt, hint, isDefault, normalizer, obj, ok, p, passphrase, prompt, res, res2, stderr, thrower, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  97. __iced_k = __iced_k_noop;
  98. ___iced_passed_deferral = iced.findDeferral(arguments);
  99. prompt = _arg.prompt, passphrase = _arg.passphrase, checker = _arg.checker, confirm = _arg.confirm, defval = _arg.defval, thrower = _arg.thrower, first_prompt = _arg.first_prompt, hint = _arg.hint, normalizer = _arg.normalizer, stderr = _arg.stderr;
  100. err = null;
  101. ok = false;
  102. first = true;
  103. (function(_this) {
  104. return (function(__iced_k) {
  105. var _results, _while;
  106. _results = [];
  107. _while = function(__iced_k) {
  108. var _break, _continue, _next;
  109. _break = function() {
  110. return __iced_k(_results);
  111. };
  112. _continue = function() {
  113. return iced.trampoline(function() {
  114. return _while(__iced_k);
  115. });
  116. };
  117. _next = function(__iced_next_arg) {
  118. _results.push(__iced_next_arg);
  119. return _continue();
  120. };
  121. if (!!ok) {
  122. return _break();
  123. } else {
  124. p = first ? prompt + (first_prompt != null ? first_prompt : "") + ": " : prompt + " (" + (hint || checker.hint) + "): ";
  125. first = false;
  126. obj = {
  127. prompt: p
  128. };
  129. if (stderr != null) {
  130. obj.output = process.stderr;
  131. }
  132. if (passphrase) {
  133. obj.silent = true;
  134. obj.replace = "*";
  135. }
  136. if (((d = _this._data[k]) != null) || ((d = defval) != null)) {
  137. obj["default"] = d;
  138. obj.edit = true;
  139. }
  140. (function(__iced_k) {
  141. __iced_deferrals = new iced.Deferrals(__iced_k, {
  142. parent: ___iced_passed_deferral,
  143. filename: "/Users/max/src/keybase/node-client/src/prompter.iced",
  144. funcname: "Prompter.read_field"
  145. });
  146. read(obj, __iced_deferrals.defer({
  147. assign_fn: (function() {
  148. return function() {
  149. err = arguments[0];
  150. res = arguments[1];
  151. return isDefault = arguments[2];
  152. };
  153. })(),
  154. lineno: 42
  155. }));
  156. __iced_deferrals._fulfill();
  157. })(function() {
  158. (function(__iced_k) {
  159. if (err != null) {
  160. (function(__iced_k) {
  161. _break()
  162. })(__iced_k);
  163. } else {
  164. return __iced_k();
  165. }
  166. })(function() {
  167. if (normalizer != null) {
  168. res = normalizer(res);
  169. }
  170. (function(__iced_k) {
  171. if ((thrower != null) && ((err = thrower(k, res)) != null)) {
  172. return __iced_k(ok = true);
  173. } else {
  174. (function(__iced_k) {
  175. if (((checker != null ? checker.f : void 0) != null) && !checker.f(res)) {
  176. return __iced_k(ok = false);
  177. } else {
  178. (function(__iced_k) {
  179. if ((confirm == null) || isDefault) {
  180. return __iced_k(ok = true);
  181. } else {
  182. delete obj["default"];
  183. obj.edit = false;
  184. obj.prompt = confirm.prompt + ": ";
  185. (function(__iced_k) {
  186. __iced_deferrals = new iced.Deferrals(__iced_k, {
  187. parent: ___iced_passed_deferral,
  188. filename: "/Users/max/src/keybase/node-client/src/prompter.iced",
  189. funcname: "Prompter.read_field"
  190. });
  191. read(obj, __iced_deferrals.defer({
  192. assign_fn: (function() {
  193. return function() {
  194. err = arguments[0];
  195. return res2 = arguments[1];
  196. };
  197. })(),
  198. lineno: 56
  199. }));
  200. __iced_deferrals._fulfill();
  201. })(function() {
  202. return __iced_k(res2 !== res ? (ok = false, log.warn("Passphrases didn't match! Try again.")) : ok = true);
  203. });
  204. }
  205. })(__iced_k);
  206. }
  207. })(__iced_k);
  208. }
  209. })(function() {
  210. return _next(ok ? !isDefault || !(_this._data[k] != null) ? _this._data[k] = res : void 0 : void 0);
  211. });
  212. });
  213. });
  214. }
  215. };
  216. _while(__iced_k);
  217. });
  218. })(this)((function(_this) {
  219. return function() {
  220. return cb(err);
  221. };
  222. })(this));
  223. };
  224. return Prompter;
  225. })();
  226. strip = function(s) {
  227. var m, x;
  228. x = /^\s*(.*?)\s*$/;
  229. if ((m = s.match(x)) != null) {
  230. s = m[1];
  231. }
  232. return s;
  233. };
  234. exports.prompt_yn = function(_arg, cb) {
  235. var ch, defval, err, obj, prompt, res, ret, win, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  236. __iced_k = __iced_k_noop;
  237. ___iced_passed_deferral = iced.findDeferral(arguments);
  238. prompt = _arg.prompt, defval = _arg.defval;
  239. win = process.platform === 'win32';
  240. if (win) {
  241. defval = null;
  242. }
  243. ch = defval != null ? "[" + (defval ? 'Y' : 'y') + "/" + (!defval ? 'N' : 'n') + "]" : '[y/n]';
  244. prompt += " " + ch + " ";
  245. obj = {
  246. prompt: prompt
  247. };
  248. ret = null;
  249. err = null;
  250. (function(_this) {
  251. return (function(__iced_k) {
  252. var _results, _while;
  253. _results = [];
  254. _while = function(__iced_k) {
  255. var _break, _continue, _next;
  256. _break = function() {
  257. return __iced_k(_results);
  258. };
  259. _continue = function() {
  260. return iced.trampoline(function() {
  261. return _while(__iced_k);
  262. });
  263. };
  264. _next = function(__iced_next_arg) {
  265. _results.push(__iced_next_arg);
  266. return _continue();
  267. };
  268. if (!((ret == null) && (err == null))) {
  269. return _break();
  270. } else {
  271. (function(__iced_k) {
  272. __iced_deferrals = new iced.Deferrals(__iced_k, {
  273. parent: ___iced_passed_deferral,
  274. filename: "/Users/max/src/keybase/node-client/src/prompter.iced",
  275. funcname: "prompt_yn"
  276. });
  277. read(obj, __iced_deferrals.defer({
  278. assign_fn: (function() {
  279. return function() {
  280. err = arguments[0];
  281. return res = arguments[1];
  282. };
  283. })(),
  284. lineno: 85
  285. }));
  286. __iced_deferrals._fulfill();
  287. })(function() {
  288. return _next(err == null ? (res = strip(res), res.length === 0 ? defval != null ? ret = defval : void 0 : "yes".indexOf(res.toLowerCase()) >= 0 ? ret = true : "no".indexOf(res.toLowerCase()) >= 0 ? ret = false : void 0) : void 0);
  289. });
  290. }
  291. };
  292. _while(__iced_k);
  293. });
  294. })(this)((function(_this) {
  295. return function() {
  296. return cb(err, ret);
  297. };
  298. })(this));
  299. };
  300. exports.prompt_passphrase = function(_arg, cb) {
  301. var checker, confirm, err, extra, no_leading_space, p, prompt, seq, short, stderr, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  302. __iced_k = __iced_k_noop;
  303. ___iced_passed_deferral = iced.findDeferral(arguments);
  304. prompt = _arg.prompt, confirm = _arg.confirm, extra = _arg.extra, short = _arg.short, no_leading_space = _arg.no_leading_space, stderr = _arg.stderr;
  305. if (prompt == null) {
  306. prompt = "Your keybase login passphrase";
  307. if (extra != null) {
  308. prompt += extra;
  309. }
  310. }
  311. checker = short ? checkers.passphrase_short : no_leading_space ? checkers.passphrase_nls : checkers.passphrase;
  312. seq = {
  313. passphrase: {
  314. prompt: prompt,
  315. passphrase: true,
  316. checker: checker,
  317. confirm: confirm,
  318. stderr: stderr
  319. }
  320. };
  321. p = new Prompter(seq);
  322. (function(_this) {
  323. return (function(__iced_k) {
  324. __iced_deferrals = new iced.Deferrals(__iced_k, {
  325. parent: ___iced_passed_deferral,
  326. filename: "/Users/max/src/keybase/node-client/src/prompter.iced",
  327. funcname: "prompt_passphrase"
  328. });
  329. p.run(__iced_deferrals.defer({
  330. assign_fn: (function() {
  331. return function() {
  332. return err = arguments[0];
  333. };
  334. })(),
  335. lineno: 115
  336. }));
  337. __iced_deferrals._fulfill();
  338. });
  339. })(this)((function(_this) {
  340. return function() {
  341. return cb(err, p.data().passphrase);
  342. };
  343. })(this));
  344. };
  345. exports.prompt_remote_name = function(_arg, cb) {
  346. var checker, err, hint, p, prompt, seq, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  347. __iced_k = __iced_k_noop;
  348. ___iced_passed_deferral = iced.findDeferral(arguments);
  349. prompt = _arg.prompt, checker = _arg.checker, hint = _arg.hint;
  350. seq = {
  351. name: {
  352. prompt: prompt,
  353. checker: checker,
  354. hint: hint
  355. }
  356. };
  357. p = new Prompter(seq);
  358. (function(_this) {
  359. return (function(__iced_k) {
  360. __iced_deferrals = new iced.Deferrals(__iced_k, {
  361. parent: ___iced_passed_deferral,
  362. filename: "/Users/max/src/keybase/node-client/src/prompter.iced",
  363. funcname: "prompt_remote_name"
  364. });
  365. p.run(__iced_deferrals.defer({
  366. assign_fn: (function() {
  367. return function() {
  368. return err = arguments[0];
  369. };
  370. })(),
  371. lineno: 123
  372. }));
  373. __iced_deferrals._fulfill();
  374. });
  375. })(this)((function(_this) {
  376. return function() {
  377. return cb(err, p.data().name);
  378. };
  379. })(this));
  380. };
  381. exports.prompt_email_or_username = function(cb) {
  382. var err, out, p, seq, v, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  383. __iced_k = __iced_k_noop;
  384. ___iced_passed_deferral = iced.findDeferral(arguments);
  385. seq = {
  386. email_or_username: {
  387. prompt: "Your keybase username or email",
  388. checker: checkers.email_or_username
  389. }
  390. };
  391. p = new Prompter(seq);
  392. (function(_this) {
  393. return (function(__iced_k) {
  394. __iced_deferrals = new iced.Deferrals(__iced_k, {
  395. parent: ___iced_passed_deferral,
  396. filename: "/Users/max/src/keybase/node-client/src/prompter.iced",
  397. funcname: "prompt_email_or_username"
  398. });
  399. p.run(__iced_deferrals.defer({
  400. assign_fn: (function() {
  401. return function() {
  402. return err = arguments[0];
  403. };
  404. })(),
  405. lineno: 134
  406. }));
  407. __iced_deferrals._fulfill();
  408. });
  409. })(this)((function(_this) {
  410. return function() {
  411. if (typeof err !== "undefined" && err !== null) {
  412. out = {};
  413. } else {
  414. v = p.data().email_or_username;
  415. out = {
  416. email: (checkers.email.f(v) ? v : null),
  417. username: (checkers.username.f(v) ? v : null)
  418. };
  419. }
  420. return cb(err, out);
  421. };
  422. })(this));
  423. };
  424. exports.prompt_for_int = function(_arg, cb) {
  425. var d, defint, err, first_prompt, hi, hint, low, out, p, prompt, seq, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  426. __iced_k = __iced_k_noop;
  427. ___iced_passed_deferral = iced.findDeferral(arguments);
  428. prompt = _arg.prompt, low = _arg.low, hi = _arg.hi, defint = _arg.defint, hint = _arg.hint, first_prompt = _arg.first_prompt;
  429. seq = {
  430. key: {
  431. prompt: prompt,
  432. checker: checkers.intcheck(low, hi, defint),
  433. hint: hint,
  434. first_prompt: first_prompt
  435. }
  436. };
  437. p = new Prompter(seq);
  438. (function(_this) {
  439. return (function(__iced_k) {
  440. __iced_deferrals = new iced.Deferrals(__iced_k, {
  441. parent: ___iced_passed_deferral,
  442. filename: "/Users/max/src/keybase/node-client/src/prompter.iced",
  443. funcname: "prompt_for_int"
  444. });
  445. p.run(__iced_deferrals.defer({
  446. assign_fn: (function() {
  447. return function() {
  448. return err = arguments[0];
  449. };
  450. })(),
  451. lineno: 153
  452. }));
  453. __iced_deferrals._fulfill();
  454. });
  455. })(this)((function(_this) {
  456. return function() {
  457. out = typeof err !== "undefined" && err !== null ? null : (d = p.data().key) === '' && (defint != null) ? defint : parseInt(d);
  458. return cb(err, out);
  459. };
  460. })(this));
  461. };
  462. }).call(this);