switch.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var ArgumentParser, Base, Command, E, add_option_dict, iced, log, make_esc, prompt_yn, reset, session, __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. session = require('../session');
  13. make_esc = require('iced-error').make_esc;
  14. prompt_yn = require('../prompter').prompt_yn;
  15. log = require('../log');
  16. E = require('../err').E;
  17. reset = require('../setup').reset;
  18. exports.Command = Command = (function(_super) {
  19. __extends(Command, _super);
  20. function Command() {
  21. return Command.__super__.constructor.apply(this, arguments);
  22. }
  23. Command.prototype.OPTS = {
  24. f: {
  25. alias: 'force',
  26. action: 'storeTrue',
  27. help: "don't prompt for approval; force it"
  28. }
  29. };
  30. Command.prototype.use_session = function() {
  31. return true;
  32. };
  33. Command.prototype.add_subcommand_parser = function(scp) {
  34. var name, opts, sub;
  35. opts = {
  36. aliases: [],
  37. help: "switch to a different user, and nuke the current state"
  38. };
  39. name = "switch";
  40. sub = scp.addParser(name, opts);
  41. sub.addArgument(["username"], {
  42. nargs: 1
  43. });
  44. add_option_dict(sub, this.OPTS);
  45. return opts.aliases.concat([name]);
  46. };
  47. Command.prototype.prompt_yn = function(cb) {
  48. var args, err, ret, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  49. __iced_k = __iced_k_noop;
  50. ___iced_passed_deferral = iced.findDeferral(arguments);
  51. err = null;
  52. (function(_this) {
  53. return (function(__iced_k) {
  54. if (!_this.argv.force) {
  55. args = {
  56. prompt: "DANGER! Log yourself out, deregister this client, and remove local cache?",
  57. defval: false
  58. };
  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/command/switch.iced",
  63. funcname: "Command.prompt_yn"
  64. });
  65. prompt_yn(args, __iced_deferrals.defer({
  66. assign_fn: (function() {
  67. return function() {
  68. err = arguments[0];
  69. return ret = arguments[1];
  70. };
  71. })(),
  72. lineno: 47
  73. }));
  74. __iced_deferrals._fulfill();
  75. })(function() {
  76. return __iced_k(!ret ? err = new E.CancelError("no go-ahead given") : void 0);
  77. });
  78. } else {
  79. return __iced_k();
  80. }
  81. });
  82. })(this)((function(_this) {
  83. return function() {
  84. return cb(err);
  85. };
  86. })(this));
  87. };
  88. Command.prototype.run = function(cb) {
  89. var esc, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  90. __iced_k = __iced_k_noop;
  91. ___iced_passed_deferral = iced.findDeferral(arguments);
  92. esc = make_esc(cb, "run");
  93. (function(_this) {
  94. return (function(__iced_k) {
  95. __iced_deferrals = new iced.Deferrals(__iced_k, {
  96. parent: ___iced_passed_deferral,
  97. filename: "/Users/max/src/keybase/node-client/src/command/switch.iced",
  98. funcname: "Command.run"
  99. });
  100. _this.prompt_yn(esc(__iced_deferrals.defer({
  101. lineno: 55
  102. })));
  103. __iced_deferrals._fulfill();
  104. });
  105. })(this)((function(_this) {
  106. return function() {
  107. (function(__iced_k) {
  108. __iced_deferrals = new iced.Deferrals(__iced_k, {
  109. parent: ___iced_passed_deferral,
  110. filename: "/Users/max/src/keybase/node-client/src/command/switch.iced",
  111. funcname: "Command.run"
  112. });
  113. reset({
  114. new_username: _this.argv.username[0]
  115. }, esc(__iced_deferrals.defer({
  116. lineno: 56
  117. })));
  118. __iced_deferrals._fulfill();
  119. })(function() {
  120. log.info("success!");
  121. return cb(null);
  122. });
  123. };
  124. })(this));
  125. };
  126. return Command;
  127. })(Base);
  128. }).call(this);