Permalink
Browse files

[ddoc] wraps up design docs

  • Loading branch information...
1 parent 3c8b154 commit a211f34bfb4647e224806b239702a0b02a74d656 @dscape committed Jun 12, 2012
Showing with 59 additions and 22 deletions.
  1. +40 −20 commands/design.js
  2. +0 −1 commands/index.js
  3. 0 commands/query.js
  4. +1 −1 config.js
  5. +18 −0 helpers.js
View
@@ -3,23 +3,6 @@ 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;
@@ -34,7 +17,7 @@ design.list = function () {
params.startkey = "_design/";
params.endkey = "_design0";
- db.list(params, generic_cb(callback));
+ db.list(params, helpers.generic_cb(callback));
};
design.get = function (name) {
@@ -59,5 +42,42 @@ design.get = function (name) {
name = "_design/" + name;
- db.get(name, params, generic_cb(callback));
-};
+ db.get(name, params, helpers.generic_cb(callback));
+};
+
+design.query = function (design, view) {
+ var err;
+
+ if(typeof design === "function") {
+ err = new Error("You didn't provide a design document name.");
+ return design(err);
+ }
+
+ if(typeof view === "function") {
+ err = new Error("You didn't provide a view name.");
+ return view(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);
+ }
+
+ db.view(design, view, params, helpers.generic_cb(callback));
+};
+
+design.usage = [
+ '',
+ '`futon config *` commands allow you to edit your',
+ 'local futon configuration file. Valid commands are:',
+ '',
+ 'futon design list <arg1=val1> <arg2=val2> ...',
+ 'futon design get <ddoc> <arg1=val1> <arg2=val2> ...',
+ 'futon design query <ddoc> <view> <arg1=val1> <arg2=val2> ...'
+];
View
@@ -1,4 +1,3 @@
var commands = exports;
-commands.query = require('./query')
commands.design = require('./design')
View
No changes.
View
@@ -51,7 +51,7 @@ futoncli.use(require('flatiron-cli-config'), {
var display = [
'Here is your ' + configFile.grey + ' file:',
'If you\'d like to change a property try:',
- 'futoncli config set <key> <value>'
+ 'futon config set <key> <value>'
];
display.forEach(function (line) {
View
@@ -1,3 +1,4 @@
+var futoncli = require('../futoncli');
var helpers = exports;
helpers.parse_args = function (args, require_cb) {
@@ -16,9 +17,26 @@ helpers.parse_args = function (args, require_cb) {
var current = args[k];
var kv;
if(typeof current === "string" && (kv = current.split("=")) && kv[1]) {
+ try { kv[1] = JSON.parse(kv[1]); } catch (ex) {}
params[kv[0]] = kv[1];
}
}
return [null, params, callback];
+};
+
+helpers.generic_cb = function (callback) {
+ return function (err, body) {
+ if(err) {
+ 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();
+ };
};

0 comments on commit a211f34

Please sign in to comment.