// Generated by IcedCoffeeScript 1.7.1-c
(function() {
  var ArgumentParser, Base, Command, E, add_option_dict, iced, log, make_esc, prompt_yn, reset, session, __iced_k, __iced_k_noop,
    __hasProp = {}.hasOwnProperty,
    __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; };

  iced = require('iced-runtime').iced;
  __iced_k = __iced_k_noop = function() {};

  Base = require('./base').Base;

  log = require('../log');

  ArgumentParser = require('argparse').ArgumentParser;

  add_option_dict = require('./argparse').add_option_dict;

  session = require('../session');

  make_esc = require('iced-error').make_esc;

  prompt_yn = require('../prompter').prompt_yn;

  log = require('../log');

  E = require('../err').E;

  reset = require('../setup').reset;

  exports.Command = Command = (function(_super) {
    __extends(Command, _super);

    function Command() {
      return Command.__super__.constructor.apply(this, arguments);
    }

    Command.prototype.OPTS = {
      f: {
        alias: 'force',
        action: 'storeTrue',
        help: "don't prompt for approval; force it"
      }
    };

    Command.prototype.use_session = function() {
      return true;
    };

    Command.prototype.use_gpg = function() {
      return false;
    };

    Command.prototype.add_subcommand_parser = function(scp) {
      var name, opts, sub;
      opts = {
        aliases: ['nuke'],
        help: "reset the local setup, deleting all local cached state"
      };
      name = "reset";
      sub = scp.addParser(name, opts);
      add_option_dict(sub, this.OPTS);
      return opts.aliases.concat([name]);
    };

    Command.prototype.prompt_yn = function(cb) {
      var args, err, ret, ___iced_passed_deferral, __iced_deferrals, __iced_k;
      __iced_k = __iced_k_noop;
      ___iced_passed_deferral = iced.findDeferral(arguments);
      err = null;
      (function(_this) {
        return (function(__iced_k) {
          if (!_this.argv.force) {
            args = {
              prompt: "DANGER! Log yourself out, deregister this client, and remove local cache?",
              defval: false
            };
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/Users/max/src/keybase/node-client/src/command/reset.iced",
                funcname: "Command.prompt_yn"
              });
              prompt_yn(args, __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return ret = arguments[1];
                  };
                })(),
                lineno: 47
              }));
              __iced_deferrals._fulfill();
            })(function() {
              return __iced_k(!ret ? err = new E.CancelError("no go-ahead given") : void 0);
            });
          } else {
            return __iced_k();
          }
        });
      })(this)((function(_this) {
        return function() {
          return cb(err);
        };
      })(this));
    };

    Command.prototype.run = function(cb) {
      var esc, ___iced_passed_deferral, __iced_deferrals, __iced_k;
      __iced_k = __iced_k_noop;
      ___iced_passed_deferral = iced.findDeferral(arguments);
      esc = make_esc(cb, "run");
      (function(_this) {
        return (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/max/src/keybase/node-client/src/command/reset.iced",
            funcname: "Command.run"
          });
          _this.prompt_yn(esc(__iced_deferrals.defer({
            lineno: 55
          })));
          __iced_deferrals._fulfill();
        });
      })(this)((function(_this) {
        return function() {
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/max/src/keybase/node-client/src/command/reset.iced",
              funcname: "Command.run"
            });
            reset({}, esc(__iced_deferrals.defer({
              lineno: 56
            })));
            __iced_deferrals._fulfill();
          })(function() {
            log.info("success!");
            return cb(null);
          });
        };
      })(this));
    };

    return Command;

  })(Base);

}).call(this);
