Skip to content

Commit

Permalink
Added command list help
Browse files Browse the repository at this point in the history
  • Loading branch information
Damon Oehlman committed Oct 11, 2012
1 parent 8bc56bc commit 389b6fe
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 58 deletions.
7 changes: 7 additions & 0 deletions assets/templates/help.txt
@@ -0,0 +1,7 @@
<%= packageData.name %> v<%= packageData.version %>:

<% if (packageData.description) { %> <%= packageData.description %><% } %>

commands:
<% _.each(commands, function(command, name) { %>
<%= _.rpad(name + ':', 14) %><%= command.desc %> <% }); %>
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -213,7 +213,7 @@ Scaffolder.prototype.main = function(opts, handler) {
}); });


// use the default commands if we have not parsed out valid commands // use the default commands if we have not parsed out valid commands
if (Array.isArray(opts.commands) && opts.commands.length === 0) { if (Array.isArray(opts.commands) && opts.commands.length === 0 && (! opts.help)) {
debug('no commands specified, attempting to use default commands: ', opts.defaultCommands); debug('no commands specified, attempting to use default commands: ', opts.defaultCommands);


// return only default commands that actually exist // return only default commands that actually exist
Expand Down
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -12,19 +12,19 @@
"dependencies": { "dependencies": {
"async": "0.1.x", "async": "0.1.x",
"debug": "*", "debug": "*",
"nopt": "1.0.x", "nopt": "2.0.x",
"out": "0.4.x", "out": "0.4.x",
"read": "0.1.x", "read": "0.1.x",
"squirrel": "0.1.x", "squirrel": "0.1.x",
"underscore": "1.3.x" "underscore": "1.3.x",
"underscore.string": "2.3.x"
}, },
"pluginDependencies": { "pluginDependencies": {
"mkdirp": "0.3.x", "mkdirp": "0.3.x",
"ncp": "0.2.6" "ncp": "0.2.6"
}, },
"devDependencies": { "devDependencies": {
"mocha": "1.2.x", "mocha": "1.5.x"
"expect.js": "0.1.x"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
Expand Down
26 changes: 20 additions & 6 deletions plugins/help.js
@@ -1,8 +1,16 @@
var debug = require('debug')('scaffolder'), var debug = require('debug')('scaffolder'),
_ = require('underscore'); _ = require('underscore'),
path = require('path'),
fs = require('fs'),
pathTemplates = path.resolve(__dirname, '..', 'assets', 'templates');

// include underscore string functions
_.mixin(require('underscore.string').exports());


module.exports = function(commandList, callback) { module.exports = function(commandList, callback) {
var command, helpText = ''; var command,
helpText = '',
scaffolder = this;


// if we have 0 commands specified, then produce the command list help // if we have 0 commands specified, then produce the command list help
if (commandList.length > 0) { if (commandList.length > 0) {
Expand All @@ -11,12 +19,18 @@ module.exports = function(commandList, callback) {


// if we have a command, then provide help on the command // if we have a command, then provide help on the command
if (typeof command == 'object') { if (typeof command == 'object') {
helpText = command.help || command.description; callback(null, command.help || command.description);
} }
else { else {
debug('generating help for commands: ', Object.keys(this.commands)); debug('generating help for commands: ', Object.keys(this.commands));
helpText = 'TODO: list the commands'; fs.readFile(path.join(pathTemplates, 'help.txt'), 'utf8', function(err, data) {
if (err) return callback(err);

callback(null, _.template(data, {
packageData: scaffolder.packageData,
lineBreak: '=========================================================================',
commands: scaffolder.commands
}));
});
} }

callback(null, helpText);
}; };
38 changes: 0 additions & 38 deletions plugins/loadTemplate.js

This file was deleted.

9 changes: 0 additions & 9 deletions test/assets.js
Expand Up @@ -20,13 +20,4 @@ describe('asset loading tests', function() {
done(err); done(err);
}); });
}); });

it('should be able to load a template (using the default engine)', function(done) {
scaffolder.loadTemplate('test-template.txt', function(err, template) {
assert.ifError(err);
assert.equal(typeof template, 'function');
assert.equal(template({ val: 'test' }), 'test');
done(err);
});
});
}); });

0 comments on commit 389b6fe

Please sign in to comment.