// Generated by IcedCoffeeScript 1.7.1-c
(function() {
  var BufferInStream, BufferOutStream, Command, TrackSubSubCommand, add_option_dict, dv, env, iced, keypull, log, __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; };

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

  dv = require('./decrypt_and_verify');

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

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

  _ref = require('iced-spawn'), BufferOutStream = _ref.BufferOutStream, BufferInStream = _ref.BufferInStream;

  TrackSubSubCommand = require('../tracksubsub').TrackSubSubCommand;

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

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

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

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

    Command.prototype.add_subcommand_parser = function(scp) {
      var name, opts, sub;
      opts = {
        aliases: ["dec"],
        help: "decrypt a file"
      };
      name = "decrypt";
      sub = scp.addParser(name, opts);
      add_option_dict(sub, dv.Command.OPTS);
      add_option_dict(sub, {
        o: {
          alias: "output",
          help: "output to the given file"
        }
      });
      sub.addArgument(["file"], {
        nargs: '?'
      });
      return opts.aliases.concat([name]);
    };

    Command.prototype.do_output = function(out, cb) {
      var ___iced_passed_deferral, __iced_deferrals, __iced_k;
      __iced_k = __iced_k_noop;
      ___iced_passed_deferral = iced.findDeferral(arguments);
      (function(_this) {
        return (function(__iced_k) {
          if (_this.argv.base64) {
            return __iced_k(log.console.log(out.toString('base64')));
          } else {
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/Users/max/src/keybase/node-client/src/command/decrypt.iced",
                funcname: "Command.do_output"
              });
              process.stdout.write(out, __iced_deferrals.defer({
                lineno: 35
              }));
              __iced_deferrals._fulfill();
            })(__iced_k);
          }
        });
      })(this)((function(_this) {
        return function() {
          return cb();
        };
      })(this));
    };

    Command.prototype.is_batch = function() {
      return !(this.argv.message != null) && !(this.argv.file != null);
    };

    Command.prototype.do_keypull = 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/decrypt.iced",
            funcname: "Command.do_keypull"
          });
          keypull({
            stdin_blocked: _this.is_batch(),
            need_secret: true
          }, __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                return err = arguments[0];
              };
            })(),
            lineno: 45
          }));
          __iced_deferrals._fulfill();
        });
      })(this)((function(_this) {
        return function() {
          _this._ran_keypull = true;
          return cb(err);
        };
      })(this));
    };

    Command.prototype.patch_gpg_args = function(args) {
      return args.push("--decrypt", "--yes");
    };

    Command.prototype.get_files = function(args) {
      var f;
      if ((f = this.argv.file) != null) {
        args.push(f);
        return true;
      } else {
        return false;
      }
    };

    return Command;

  })(dv.Command);

}).call(this);
