config.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var ArgumentParser, Base, Command, E, PackageJson, a_json_parse, add_option_dict, convert, env, gpg, iced, log, urlmod, __iced_k, __iced_k_noop,
  4. __hasProp = {}.hasOwnProperty,
  5. __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; };
  6. iced = require('iced-runtime').iced;
  7. __iced_k = __iced_k_noop = function() {};
  8. Base = require('./base').Base;
  9. log = require('../log');
  10. ArgumentParser = require('argparse').ArgumentParser;
  11. add_option_dict = require('./argparse').add_option_dict;
  12. PackageJson = require('../package').PackageJson;
  13. gpg = require('gpg-wrapper').gpg;
  14. E = require('../err').E;
  15. env = require('../env').env;
  16. a_json_parse = require('iced-utils').util.a_json_parse;
  17. urlmod = require('url');
  18. convert = function(s) {
  19. var i;
  20. if (s == null) {
  21. return null;
  22. } else if (s === 'true') {
  23. return true;
  24. } else if (s === 'false') {
  25. return false;
  26. } else if (s.match(/^[0-9]+$/) && !(isNaN(i = parseInt(s, 10)))) {
  27. return i;
  28. } else {
  29. return s;
  30. }
  31. };
  32. exports.Command = Command = (function(_super) {
  33. __extends(Command, _super);
  34. function Command() {
  35. return Command.__super__.constructor.apply(this, arguments);
  36. }
  37. Command.prototype.OPTS = {
  38. get: {
  39. help: "Read the given configuration option"
  40. },
  41. j: {
  42. alias: 'json',
  43. help: 'interpret the value as JSON',
  44. action: 'storeTrue'
  45. },
  46. pretty: {
  47. help: "pretty-print JSON",
  48. action: 'storeTrue'
  49. },
  50. s: {
  51. alias: "server",
  52. help: "specify which server to use"
  53. },
  54. S: {
  55. alias: "reset-server",
  56. help: "reset the server to default",
  57. action: 'storeTrue'
  58. }
  59. };
  60. Command.prototype.add_subcommand_parser = function(scp) {
  61. var name, opts, sub;
  62. opts = {
  63. aliases: [],
  64. help: "make an initial configuration file"
  65. };
  66. name = "config";
  67. sub = scp.addParser(name, opts);
  68. add_option_dict(sub, this.OPTS);
  69. sub.addArgument(["kvs"], {
  70. nargs: "*"
  71. });
  72. return opts.aliases.concat([name]);
  73. };
  74. Command.prototype.config_opts = function() {
  75. return {
  76. quiet: true
  77. };
  78. };
  79. Command.prototype.use_gpg = function() {
  80. return false;
  81. };
  82. Command.prototype.run = function(cb) {
  83. var c, err, h, k, msg, p, pjs, s, url, v, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  84. __iced_k = __iced_k_noop;
  85. ___iced_passed_deferral = iced.findDeferral(arguments);
  86. err = null;
  87. c = env().config;
  88. (function(_this) {
  89. return (function(__iced_k) {
  90. if ((k = _this.argv.get) != null) {
  91. return __iced_k(console.log(JSON.stringify(c.get(k), null, (_this.argv.pretty ? " " : null))));
  92. } else {
  93. (function(__iced_k) {
  94. if ((s = _this.argv.server) != null) {
  95. return __iced_k((url = urlmod.parse(s)) != null ? (url.protocol === "http:" ? c.set("server.no_tls", true) : void 0, (p = url.port) != null ? c.set("server.port", parseInt(p, 10)) : void 0, (h = url.hostname) != null ? c.set("server.host", h) : void 0) : (msg = "Couldn't parse server URL " + url, log.error(msg), err = new E.ArgsError(msg)));
  96. } else {
  97. (function(__iced_k) {
  98. if (_this.argv.reset_server) {
  99. return __iced_k(c.set("server", null));
  100. } else {
  101. (function(__iced_k) {
  102. if (_this.argv.kvs.length > 2) {
  103. msg = "Need either 0,1 or 2 arguments for setting values in config";
  104. log.error("Usage: " + msg);
  105. return __iced_k(err = new E.ArgsError(msg));
  106. } else {
  107. (function(__iced_k) {
  108. if (_this.argv.kvs.length > 0) {
  109. k = _this.argv.kvs[0];
  110. (function(__iced_k) {
  111. if (_this.argv.json && (_this.argv.kvs.length === 2)) {
  112. (function(__iced_k) {
  113. __iced_deferrals = new iced.Deferrals(__iced_k, {
  114. parent: ___iced_passed_deferral,
  115. filename: "/home/max/src/keybase/node-client/src/command/config.iced",
  116. funcname: "Command.run"
  117. });
  118. a_json_parse(_this.argv.kvs[1], __iced_deferrals.defer({
  119. assign_fn: (function() {
  120. return function() {
  121. err = arguments[0];
  122. return v = arguments[1];
  123. };
  124. })(),
  125. lineno: 86
  126. }));
  127. __iced_deferrals._fulfill();
  128. })(__iced_k);
  129. } else {
  130. return __iced_k(v = convert(_this.argv.kvs.length === 2 ? _this.argv.kvs[1] : null));
  131. }
  132. })(function() {
  133. return __iced_k(err == null ? c.set(k, v) : void 0);
  134. });
  135. } else {
  136. return __iced_k(c.is_empty() ? (pjs = new PackageJson(), c.set("generated", {
  137. by: "keybase v" + (pjs.version()),
  138. on: (new Date()).toString()
  139. })) : log.warn("keybase has already been initialized; see '" + c.filename + "'"));
  140. }
  141. })(__iced_k);
  142. }
  143. })(__iced_k);
  144. }
  145. })(__iced_k);
  146. }
  147. })(__iced_k);
  148. }
  149. });
  150. })(this)((function(_this) {
  151. return function() {
  152. (function(__iced_k) {
  153. if (!err && c.is_dirty()) {
  154. (function(__iced_k) {
  155. __iced_deferrals = new iced.Deferrals(__iced_k, {
  156. parent: ___iced_passed_deferral,
  157. filename: "/home/max/src/keybase/node-client/src/command/config.iced",
  158. funcname: "Command.run"
  159. });
  160. c.write(__iced_deferrals.defer({
  161. assign_fn: (function() {
  162. return function() {
  163. return err = arguments[0];
  164. };
  165. })(),
  166. lineno: 99
  167. }));
  168. __iced_deferrals._fulfill();
  169. })(__iced_k);
  170. } else {
  171. return __iced_k();
  172. }
  173. })(function() {
  174. return cb(err);
  175. });
  176. };
  177. })(this));
  178. };
  179. return Command;
  180. })(Base);
  181. }).call(this);