// Generated by IcedCoffeeScript 1.7.1-c
(function() {
  var ArgumentParser, Base, Command, E, PackageJson, S, User, add_option_dict, assert, iced, log, make_esc, prompt_remote_name, prompt_yn, req, session, __iced_k, __iced_k_noop, _ref,
    __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; },
    __slice = [].slice;

  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;

  PackageJson = require('../package').PackageJson;

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

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

  _ref = require('../prompter'), prompt_yn = _ref.prompt_yn, prompt_remote_name = _ref.prompt_remote_name;

  User = require('../user').User;

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

  assert = require('assert');

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

  S = require('../services');

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

    function Command() {
      var args;
      args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
      Command.__super__.constructor.apply(this, args);
      this.supersede = false;
    }

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

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

    Command.OPTS = {
      f: {
        alias: 'force',
        action: 'storeTrue',
        help: "don't stop for any prompts"
      }
    };

    Command.prototype.add_subcommand_parser = function(scp) {
      var OPTS, config, name, sub, _ref1;
      _ref1 = this.command_name_and_opts(), name = _ref1.name, config = _ref1.config, OPTS = _ref1.OPTS;
      sub = scp.addParser(name, config);
      add_option_dict(sub, OPTS);
      sub.addArgument(["service"], {
        nargs: 1,
        help: "the name of service; can be one of: {twitter,github,web,dns,reddit,coinbase,hackernews}"
      });
      sub.addArgument(["remote_name"], {
        nargs: "?",
        help: "username or hostname at that service"
      });
      return config.aliases.concat([name]);
    };

    Command.prototype.prompt_remote_name = function(cb) {
      var err, ret, svc, ___iced_passed_deferral, __iced_deferrals, __iced_k;
      __iced_k = __iced_k_noop;
      ___iced_passed_deferral = iced.findDeferral(arguments);
      svc = this.argv.service[0];
      err = null;
      ret = null;
      (function(_this) {
        return (function(__iced_k) {
          if (_this.remote_name == null) {
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/home/max/src/keybase/node-client/src/command/proof_base.iced",
                funcname: "Command.prompt_remote_name"
              });
              prompt_remote_name(_this.stub.prompter(), __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return ret = arguments[1];
                  };
                })(),
                lineno: 54
              }));
              __iced_deferrals._fulfill();
            })(function() {
              return __iced_k(err == null ? _this.remote_name = ret : void 0);
            });
          } else {
            return __iced_k();
          }
        });
      })(this)((function(_this) {
        return function() {
          return cb(err, ret);
        };
      })(this));
    };

    Command.prototype.normalize_remote_name = 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: "/home/max/src/keybase/node-client/src/command/proof_base.iced",
            funcname: "Command.normalize_remote_name"
          });
          _this.stub.normalize_name(_this.remote_name, __iced_deferrals.defer({
            assign_fn: (function(__slot_1) {
              return function() {
                err = arguments[0];
                return __slot_1.remote_name_normalized = arguments[1];
              };
            })(_this),
            lineno: 61
          }));
          __iced_deferrals._fulfill();
        });
      })(this)((function(_this) {
        return function() {
          return cb(err);
        };
      })(this));
    };

    Command.prototype.allocate_proof_gen = function(cb) {
      var err, klass, ___iced_passed_deferral, __iced_deferrals, __iced_k;
      __iced_k = __iced_k_noop;
      ___iced_passed_deferral = iced.findDeferral(arguments);
      klass = S.classes[this.service_name];
      assert.ok(klass != null);
      (function(_this) {
        return (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/max/src/keybase/node-client/src/command/proof_base.iced",
            funcname: "Command.allocate_proof_gen"
          });
          _this.me.gen_remote_proof_gen({
            klass: _this.klass,
            remote_name_normalized: _this.remote_name_normalized,
            supersede: _this.supersede
          }, __iced_deferrals.defer({
            assign_fn: (function(__slot_1) {
              return function() {
                err = arguments[0];
                return __slot_1.gen = arguments[1];
              };
            })(_this),
            lineno: 69
          }));
          __iced_deferrals._fulfill();
        });
      })(this)((function(_this) {
        return function() {
          return cb(err);
        };
      })(this));
    };

    Command.prototype.parse_args = function(cb) {
      var err, s;
      err = null;
      if ((s = S.aliases[this.argv.service[0].toLowerCase()]) != null) {
        this.service_name = s;
        this.klass = S.classes[s];
        assert.ok(this.klass != null);
        this.stub = new this.klass({});
      } else {
        err = new E.UnknownServiceError("Unknown service: " + this.argv.service[0]);
      }
      if ((err == null) && ((this.remote_name = this.argv.remote_name) != null) && !this.stub.check_name_input(this.remote_name)) {
        err = new E.ArgsError("Bad name " + this.argv.service[0] + " given: " + this.remote_name);
      }
      return cb(err);
    };

    return Command;

  })(Base);

}).call(this);
