Browse files

added document content function and travis stuff

  • Loading branch information...
1 parent c49c8d1 commit f8e3ce1e1c388f2bd9654a77178ec76165b8fd7f @stefanjudis committed Mar 22, 2013
Showing with 31 additions and 43 deletions.
  1. +11 −1 lib/callbacks/documentCallbacks.js
  2. +18 −41 lib/commands/documentCommands.js
  3. +1 −0 lib/commands/generalCommands.js
  4. +1 −1 package.json
View
12 lib/callbacks/documentCallbacks.js
@@ -16,6 +16,17 @@ var documentCallbacks = module.exports = {},
extend(documentCallbacks, generalCallbacks);
+documentCallbacks.content = function(error, document) {
+ if (typeof document.id === 'function') {
+ console.log(clc.yellow('\nProperty set.\n'));
+ } else {
+ console.pretty(document);
+ }
+
+ cli.prompt();
+};
+
+
documentCallbacks.load = function(error, document) {
if (error) {
documentCallbacks.showError(error);
@@ -33,7 +44,6 @@ documentCallbacks.save = function(error, document) {
//cli.doc._id = document_id;
}
-
cli.prompt();
};
View
59 lib/commands/documentCommands.js
@@ -35,49 +35,26 @@ extend(documentCommands, generalCommands);
*/
documentCommands._content = function(input, cli) {
var args = input.slice(1, input.length),
- argsLength = args.length,
- // TOTO use body function
- body = cli.doc._body,
- bodyKeys = Object.keys(body),
- response = {};
-
- switch (argsLength) {
- case 0:
- if (bodyKeys.length === 0) {
- console.log(
- clc.red('\nNo entries found. Probably document not loaded yet.\n')
- );
- } else {
- console.pretty(cli.doc._body);
- }
-
- break;
- case 1:
- if (body[args[0]] !== undefined) {
- response[args[0]] = body[args[0]];
-
- console.pretty(response);
- } else {
- console.log(
- clc.red('Key not found in document. May mispelled something?')
- );
- }
- break;
- case 2:
- body[args[0]] = args[1];
- console.log(
- clc.yellow(args[1] + ' saved to ' + args[0] + '.')
- );
- break;
- default:
- console.log(
- clc.red(
- '\nToo many arguments. Try $ help document for further information.\n'
- )
- );
+ response;
+
+ response = cli.doc.body.apply(cli.doc, args);
+
+ if (typeof response === 'object' && Object.keys(response).length === 0) {
+ console.log(
+ clc.red(
+ 'The response is empty.\n' +
+ 'Maybe you forgot to \'load\' the document before?'
+ )
+ );
+
+ cli.prompt();
}
- cli.prompt();
+ documentCallbacks.content(
+ false,
+ response
+ );
+
};
View
1 lib/commands/generalCommands.js
@@ -179,6 +179,7 @@ generalCommands._help = function(input, cli) {
* @param {Object} cli general cli object
*
* @private
+ * @tested
*/
generalCommands._listDatabases = function(input, cli) {
cli.cushion.listDatabases(connectionCallbacks.listDatabases);
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "cushion-cli",
"description": "Command line tool for CouchDB based on cushion.",
- "version": "0.1.0",
+ "version": "0.1.1",
"homepage": "https://github.com/stefanjudis/cushion-cli",
"author": {
"name": "stefan judis",

0 comments on commit f8e3ce1

Please sign in to comment.