Permalink
Browse files

Commands initialization should happen in cli module

  • Loading branch information...
RStankov committed Feb 7, 2012
1 parent 8e8f186 commit 24d594f748daca42fa0703fdbea2d8699e4870b1
Showing with 20 additions and 15 deletions.
  1. +2 −2 lib/cli.js
  2. +11 −4 lib/commands.js
  3. +7 −9 test/commands.test.js
View
@@ -10,14 +10,14 @@
*
* @type {Object}
*/
-var app = module.exports = require('./app')
+var app = module.exports = require('./app');
/**
* Commands.
*
* @type {Object}
*/
-var commands = require('./commands');
+var commands = require('./commands').init(require('./todos').init(require('./storage')));
// Version.
app.cmd(/version/, commands.version);
View
@@ -12,9 +12,6 @@
*/
var commands = module.exports;
-commands.storage = require('./storage');
-commands.todos = require('./todos').init(commands.storage);
-
/**
* Print alias.
*
@@ -30,7 +27,7 @@ commands.print = function(value) {
* @api private
*/
commands.format = function(items) {
- return "\n" + items.map(format).join("\n") + "\n"
+ return "\n" + items.map(format).join("\n") + "\n";
};
/**
@@ -52,6 +49,16 @@ var format = require('./formatter').format;
*/
var fs = require('fs');
+/**
+ * Initializes the commands by given todos.
+ *
+ * @api public
+ */
+commands.init = function(todos) {
+ commands.todos = todos;
+ return commands;
+}
+
/**
* Prints current version.
*
View
@@ -5,19 +5,17 @@
* MIT License.
*/
-var sinon = require('sinon'),
- commands = require('../lib/commands'),
- Todos = require('../lib/todos'),
- Storage = require('./support/fake_storage');
+var sinon = require('sinon'),
+ init = require('../lib/commands').init,
+ Todos = require('../lib/todos'),
+ Storage = require('./support/fake_storage');
describe('commands', function() {
- var storage;
+ var storage, commands;
beforeEach(function() {
- commands.storage = new Storage();
- commands.todos = new Todos(commands.storage);
-
- storage = commands.storage;
+ storage = new Storage();
+ commands = init(new Todos(storage));
});
describe('version', function() {

0 comments on commit 24d594f

Please sign in to comment.