// Generated by IcedCoffeeScript 1.7.1-c
(function() {
  var Command, E, add_option_dict, iced, make_esc, pg, prompt_yn, __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() {};

  pg = require('./push_and_keygen');

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

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

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

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

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

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

    Command.prototype.OPTS = {
      p: {
        alias: "push",
        action: "storeTrue",
        help: "true if we should push"
      }
    };

    Command.prototype.add_subcommand_parser = function(scp) {
      var name, opts, sub;
      opts = {
        aliases: ['gen', 'generate'],
        help: "generate a new PGP public key and optionally push it to the server"
      };
      name = "keygen";
      sub = scp.addParser(name, opts);
      add_option_dict(sub, this.OPTS);
      add_option_dict(sub, pg.Command.OPTS);
      return opts.aliases.concat([name]);
    };

    Command.prototype.check_args = function(cb) {
      var err;
      err = null;
      if (this.argv.search && this.argv.gen) {
        err = new E.ArgsError("Can't both search and generate; pick one or the other!");
      }
      return cb(err);
    };

    Command.prototype.should_push = function(cb) {
      var err, ret, ___iced_passed_deferral, __iced_deferrals, __iced_k;
      __iced_k = __iced_k_noop;
      ___iced_passed_deferral = iced.findDeferral(arguments);
      err = ret = null;
      (function(_this) {
        return (function(__iced_k) {
          if (_this.argv.push) {
            return __iced_k(ret = true);
          } else {
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/Users/max/src/keybase/node-client/src/command/keygen.iced",
                funcname: "Command.should_push"
              });
              prompt_yn({
                prompt: "Push your public key to the server?",
                defval: true
              }, __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return ret = arguments[1];
                  };
                })(),
                lineno: 42
              }));
              __iced_deferrals._fulfill();
            })(__iced_k);
          }
        });
      })(this)((function(_this) {
        return function() {
          return cb(err, ret);
        };
      })(this));
    };

    Command.prototype.should_push_secret = function(cb) {
      var err, ret, ___iced_passed_deferral, __iced_deferrals, __iced_k;
      __iced_k = __iced_k_noop;
      ___iced_passed_deferral = iced.findDeferral(arguments);
      err = ret = null;
      (function(_this) {
        return (function(__iced_k) {
          if (_this.argv.secret) {
            return __iced_k(ret = true);
          } else {
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/Users/max/src/keybase/node-client/src/command/keygen.iced",
                funcname: "Command.should_push_secret"
              });
              prompt_yn({
                prompt: "Push your encrypted private key to the server?",
                defval: true
              }, __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return ret = arguments[1];
                  };
                })(),
                lineno: 51
              }));
              __iced_deferrals._fulfill();
            })(__iced_k);
          }
        });
      })(this)((function(_this) {
        return function() {
          return cb(err, ret);
        };
      })(this));
    };

    Command.prototype.prepare_key = function(cb) {
      var err, ___iced_passed_deferral, __iced_deferrals, __iced_k;
      __iced_k = __iced_k_noop;
      ___iced_passed_deferral = iced.findDeferral(arguments);
      (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/keygen.iced",
            funcname: "Command.prepare_key"
          });
          _this.do_key_gen(__iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                return err = arguments[0];
              };
            })(),
            lineno: 57
          }));
          __iced_deferrals._fulfill();
        });
      })(this)((function(_this) {
        return function() {
          return cb(err);
        };
      })(this));
    };

    return Command;

  })(pg.Command);

}).call(this);
