Browse files

[futon] changed names to get npm

  • Loading branch information...
1 parent 310bac7 commit 3c8b154d8cccc1e59c8346b3e8a5ba69f83afb5d @dscape committed Jun 12, 2012
Showing with 138 additions and 92 deletions.
  1. +1 −1 bin/{futoncli → futon}
  2. +63 −0 commands/design.js
  3. +2 −0 commands/index.js
  4. 0 commands/query.js
  5. +2 −2 commands/usage.js
  6. +45 −88 futoncli.js
  7. +24 −0 helpers.js
  8. +1 −1 package.json
View
2 bin/futoncli → bin/futon
@@ -4,7 +4,7 @@ var futoncli = require('../futoncli');
futoncli.start(function (err) {
if (!err) {
- futoncli.log.info('futoncli'.grey + ' ok'.green.bold);
+ futoncli.log.info('futon'.grey + ' ok'.green.bold);
}
process.stdout.on('drain', function (err) {
View
63 commands/design.js
@@ -0,0 +1,63 @@
+var futoncli = require('../futoncli');
+var helpers = require('../helpers');
+
+var design = exports;
+
+function generic_cb(callback) {
+ return function (err, body) {
+ if(err) {
+ console.log(err, callback.toString());
+ return callback(err);
+ }
+ // iterating and showing names would be better
+ futoncli.inspect.putObject(body, {
+ password: function (line) {
+ var password = line.match(/password.*\:\s(.*)$/)[1];
+ return line.replace(password, "'********'");
+ }
+ }, 2);
+ callback();
+ };
+}
+
+design.list = function () {
+ var args = helpers.parse_args([].slice.call(arguments,0), true);
+ var db = futoncli.db;
+ var err = args[0];
+ var params = args[1];
+ var callback = args[2];
+
+ if(err) {
+ return callback(err);
+ }
+
+ params.startkey = "_design/";
+ params.endkey = "_design0";
+
+ db.list(params, generic_cb(callback));
+};
+
+design.get = function (name) {
+ var err;
+
+ if(typeof name === "function") {
+ err = new Error("You didn't provide a design document name.");
+ return name(err);
+ }
+
+
+ var args = helpers.parse_args([].slice.call(arguments, 0), true);
+ var db = futoncli.db;
+ var params = args[1];
+ var callback = args[2];
+
+ err = args[0];
+
+ if(err) {
+ return callback(err);
+ }
+
+ name = "_design/" + name;
+
+ db.get(name, params, generic_cb(callback));
+};
View
2 commands/index.js
@@ -1,2 +1,4 @@
var commands = exports;
+commands.query = require('./query')
+commands.design = require('./design')
View
0 commands/query.js
No changes.
View
4 commands/usage.js
@@ -25,9 +25,9 @@ module.exports = [
'',
'Usage:'.cyan.bold.underline,
'',
- ' futoncli <resource> <action> <param1> <param2> ...',
+ ' futon <resource> <action> <param1> <param2> ...',
'',
'Common Commands:'.cyan.bold.underline,
'',
- ' futoncli config (e.g. to set your couchdb endpoint)'
+ ' futon config (e.g. to set your couchdb endpoint)'
];
View
133 futoncli.js
@@ -17,13 +17,12 @@ futoncli.use(flatiron.plugins.cli, {
argv: {
version: {
alias: 'v',
- description: 'print futoncli version and exit',
+ description: 'print futon version and exit',
string: true
}
}
});
-
futoncli.started = false;
futoncli.commands = require('./commands');
futoncli.prompt.override = futoncli.argv;
@@ -36,10 +35,10 @@ futoncli.prompt.properties = flatiron.common.mixin(
"warning": 'Must respond yes or no',
"default": 'no'
},
- "server": {
- "name": "server",
+ "endpoint": {
+ "name": "endpoint",
"message": "CouchDB",
- "default": "http://localhost:5984"
+ "default": "http://localhost:5984/dbname"
}
}
);
@@ -48,7 +47,7 @@ require('./config');
require('./aliases');
futoncli.welcome = function () {
- futoncli.log.info('Welcome to ' + 'futoncli'.grey);
+ futoncli.log.info('Welcome to ' + 'futon'.grey);
futoncli.log.info('It worked if it ends with ' + 'futoncli'.grey + ' ok'.green.bold);
};
@@ -62,31 +61,31 @@ futoncli.start = function (callback) {
futoncli.welcome();
- var server = futoncli.config.get('server');
- if (!server) {
- return futoncli.prompt.get(["server"], function (err, stdin) {
+ var endpoint = futoncli.config.get('endpoint');
+ if (!endpoint) {
+ return futoncli.prompt.get(["endpoint"], function (err, stdin) {
if (err) {
callback(err);
return futoncli.showError.apply(
futoncli, [futoncli.argv._[0]].concat(arguments));
}
- if(typeof stdin.server === "string" &&
- /^https*:\/\//.test(stdin.server)) {
- var server = stdin.server;
- futoncli.config.set('server', server);
+ if(typeof stdin.endpoint === "string" &&
+ /^https*:\/\//.test(stdin.endpoint)) {
+ var endpoint = stdin.endpoint;
+ futoncli.config.set('endpoint', endpoint);
futoncli.config.save(function (err) {
if (err) {
callback(err);
return futoncli.showError.apply(
futoncli, [futoncli.argv._[0]].concat(err));
}
- futoncli.log.info('Configured server ' + server.magenta);
+ futoncli.log.info('Configured endpoint ' + endpoint.magenta);
return futoncli.exec(futoncli.argv._, callback);
});
} else {
- err = new Error("Bad URL. Try http://localhost:5984");
+ err = new Error("Bad URL. Try http://localhost:5984/dbname");
callback(err);
return futoncli.showError.apply(
futoncli, [futoncli.argv._[0]].concat(err));
@@ -123,7 +122,27 @@ futoncli.setup = function (callback) {
return callback();
}
- futoncli.nano = require('nano')(futoncli.config.get('server'));
+ var endpoint = futoncli.config.get('endpoint');
+
+ futoncli.db = require('nano')(futoncli.config.get('endpoint'));
+
+ if(!futoncli.db.attachment) {
+ // it would be idea to support admin functions too, like creating
+ // databases and stuff
+ //
+ // but this is it for now
+ // pull requests are welcome
+ var err = futoncli.db.db
+ ? new Error("You CouchDB endpoint doesn't seem to be a db " +
+ endpoint + ". Update your " +
+ " config with futon config set endpoint " +
+ " http://localhost:5984/sampledb")
+ : new Error("Your CouchDB Endpoint seems invalid " + endpoint);
+ callback(err);
+ return futoncli.showError.apply(
+ futoncli, ['setup'].concat(err));
+ }
+
futoncli.started = true;
callback();
@@ -132,80 +151,18 @@ futoncli.setup = function (callback) {
futoncli.showError = function (command, err, shallow, skip) {
var stack;
- if (err.statusCode === '403') {
- futoncli.log.error('403 ' + err.result.error);
- }
- else if (!skip) {
- futoncli.log.error('Error running command ' + command.magenta);
-
- if (err.message) {
- futoncli.log.error(err.message);
- }
+ futoncli.log.error('Error running command ' + command.magenta);
- if (err.result) {
- if (err.result.error) {
- futoncli.log.error(err.result.error);
- }
+ if (err.message) {
+ futoncli.log.error(err.message);
+ }
- if (err.result.result && err.result.result.error) {
- if (err.result.result.error.stderr || err.result.result.error.stdout) {
- futoncli.log.error('');
- futoncli.log.error('There was an error while attempting to start your application.');
- futoncli.log.error(err.result.result.error.message);
- if (err.result.result.error.blame) {
- futoncli.log.error(err.result.result.error.blame.message);
- futoncli.log.error('');
- futoncli.log.error('This type of error is usually a ' + err.result.result.error.blame.type + ' error.');
- }
-
- futoncli.log.error('Error output from your application:');
- futoncli.log.error('');
- if (err.result.result.error.stdout) {
- err.result.result.error.stdout.split('\n').forEach(function (line) {
- futoncli.log.error(line);
- });
- }
-
- if (err.result.result.error.stderr) {
- err.result.result.error.stderr.split('\n').forEach(function (line) {
- futoncli.log.error(line);
- });
- }
- }
- else if (err.result.result.error.stack && futoncli.config.get('debug')) {
- futoncli.log.error('There was an error while attempting to deploy your application.');
- futoncli.log.error('');
- futoncli.log.error(err.result.result.error.message);
-
- if (err.result.result.error.blame) {
- futoncli.log.error(err.result.result.error.blame.message);
- futoncli.log.error('');
- futoncli.log.error('This type of error is usually a ' + err.result.result.error.blame.type + ' error.');
- }
-
- futoncli.log.error('Error output from Haibu:');
- futoncli.log.error('');
- stack = err.result.result.error.result || err.result.result.error.stack;
- stack.split('\n').forEach(function (line) {
- futoncli.log.error(line);
- });
- }
- }
- else if (err.result.stack) {
- futoncli.log.warn('Error returned from Conservatory');
- err.result.stack.split('\n').forEach(function (line) {
- futoncli.log.error(line);
- });
- }
+ futoncli.inspect.putObject(err, {
+ password: function (line) {
+ var password = line.match(/password.*\:\s(.*)$/)[1];
+ return line.replace(password, "'********'");
}
- else {
- if (err.stack && !shallow) {
- err.stack.split('\n').forEach(function (trace) {
- futoncli.log.error(trace);
- });
- }
- }
- }
+ }, 2);
- futoncli.log.info('futoncli '.grey + 'not ok'.red.bold);
+ futoncli.log.info('futon '.grey + 'not ok'.red.bold);
};
View
24 helpers.js
@@ -0,0 +1,24 @@
+var helpers = exports;
+
+helpers.parse_args = function (args, require_cb) {
+ var callback;
+ var params = {};
+
+ if(require_cb) {
+ callback = args.pop();
+ if(typeof callback !== "function") {
+ var err = new Error("Invalid callback function: " + callback);
+ return [err];
+ }
+ }
+
+ for(var k in args) {
+ var current = args[k];
+ var kv;
+ if(typeof current === "string" && (kv = current.split("=")) && kv[1]) {
+ params[kv[0]] = kv[1];
+ }
+ }
+
+ return [null, params, callback];
+};
View
2 package.json
@@ -1,4 +1,4 @@
-{ "name" : "futoncli"
+{ "name" : "futon"
, "description" : "command line futon"
, "homepage" : "http://github.com/dscape/futoncli"
, "repository" : "git://github.com/dscape/futoncli"

0 comments on commit 3c8b154

Please sign in to comment.