// Generated by CoffeeScript 1.11.1
(function() {
  var help, option, optsSwitch, par, synopsis;

  optsSwitch = function(o) {
    var s;
    s = "-" + o.short;
    if (o.long != null) {
      s += ", --" + o.long;
    }
    if (o.argument != null) {
      s += " <" + o.argument + ">";
    }
    return s;
  };

  synopsis = function(readme) {
    var arg, s;
    return ["" + (readme.name.split('-')[0].trim()), "[option …]"].concat((function() {
      var i, len, ref, results;
      ref = readme["arguments"];
      results = [];
      for (i = 0, len = ref.length; i < len; i++) {
        arg = ref[i];
        s = arg.name;
        if (arg.moreThanOnce) {
          s += " …";
        }
        if (arg.optional) {
          s = "[" + s + "]";
        }
        results.push(s);
      }
      return results;
    })()).join(" ");
  };

  par = function(input, arg1) {
    var buf, i, indent, inputLines, j, len, len1, line, output, ref, ref1, shouldWrap, totalWidth, word, words;
    totalWidth = (ref = arg1.totalWidth) != null ? ref : process.stdout.columns, indent = (ref1 = arg1.indent) != null ? ref1 : "";
    inputLines = input.split('\n');
    buf = "";
    output = [];
    for (i = 0, len = inputLines.length; i < len; i++) {
      line = inputLines[i];
      if (line.trim().length === 0 || line.match(/^\s/)) {
        if (buf.length > 0) {
          output.push(indent + buf);
        }
        output.push(indent + line);
        buf = "";
      } else {
        words = line.split(/\s+/);
        for (j = 0, len1 = words.length; j < len1; j++) {
          word = words[j];
          shouldWrap = indent.length + buf.length + word.length + 1 > totalWidth;
          if ((buf.length > 0) && shouldWrap) {
            output.push(indent + buf);
            buf = "";
          }
          if (buf.length > 0) {
            buf += " ";
          }
          buf += word;
        }
      }
    }
    if (buf.length > 0) {
      output.push(buf);
    }
    return output.join("\n");
  };

  option = function(o) {
    return (optsSwitch(o)) + " \n  \n" + (par(o.description, {
      indent: "   "
    }));
  };

  help = function(readme) {
    var o, opts;
    opts = (function() {
      var i, len, ref, results;
      ref = readme.options;
      results = [];
      for (i = 0, len = ref.length; i < len; i++) {
        o = ref[i];
        results.push(option(o));
      }
      return results;
    })();
    return "\nSynopsis:\n\n  " + (synopsis(readme)) + "\n\nOptions:\n\n" + (opts.join("\n")) + "\n";
  };

  module.exports = help;

}).call(this);
