Permalink
Browse files

Added command list help

  • Loading branch information...
1 parent 8bc56bc commit 389b6fe6bd5cf06fbf92403e86c80d258997bbe9 @DamonOehlman committed Oct 11, 2012
Showing with 32 additions and 58 deletions.
  1. +7 −0 assets/templates/help.txt
  2. +1 −1 index.js
  3. +4 −4 package.json
  4. +20 −6 plugins/help.js
  5. +0 −38 plugins/loadTemplate.js
  6. +0 −9 test/assets.js
@@ -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 %> <% }); %>
View
@@ -213,7 +213,7 @@ Scaffolder.prototype.main = function(opts, handler) {
});
// 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);
// return only default commands that actually exist
View
@@ -12,19 +12,19 @@
"dependencies": {
"async": "0.1.x",
"debug": "*",
- "nopt": "1.0.x",
+ "nopt": "2.0.x",
"out": "0.4.x",
"read": "0.1.x",
"squirrel": "0.1.x",
- "underscore": "1.3.x"
+ "underscore": "1.3.x",
+ "underscore.string": "2.3.x"
},
"pluginDependencies": {
"mkdirp": "0.3.x",
"ncp": "0.2.6"
},
"devDependencies": {
- "mocha": "1.2.x",
- "expect.js": "0.1.x"
+ "mocha": "1.5.x"
},
"repository": {
"type": "git",
View
@@ -1,8 +1,16 @@
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) {
- var command, helpText = '';
+ var command,
+ helpText = '',
+ scaffolder = this;
// if we have 0 commands specified, then produce the command list help
if (commandList.length > 0) {
@@ -11,12 +19,18 @@ module.exports = function(commandList, callback) {
// if we have a command, then provide help on the command
if (typeof command == 'object') {
- helpText = command.help || command.description;
+ callback(null, command.help || command.description);
}
else {
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);
};
View
@@ -1,38 +0,0 @@
-module.exports = function(templateFile, opts, callback) {
- var scaffolder = this;
-
- // remap args if required
- if (typeof opts == 'function') {
- callback = opts;
- opts = {};
- }
-
- // ensure options are defined
- opts = opts || {};
-
- // initialise the default template engine to handlebars
- opts.engine = opts.engine || 'handlebars';
-
- // use squirrel to load the requested template engine
- this.squirrel(opts.engine, function(err, engine) {
- if (err) return callback(err);
-
- // read the file
- scaffolder.readFile(templateFile, 'utf8', function(err, content) {
- var template;
-
- if (err) return callback(err);
-
- // first look for a compile function in the template engine
- if (typeof engine == 'function') {
- template = engine(content);
- }
- else if (typeof engine == 'object' && typeof engine.compile == 'function') {
- template = engine.compile(content);
- }
-
- // otherwise, generate the template
- callback(template ? null : new Error('No template function found for engine "' + opts.engine + '"'), template);
- });
- });
-};
View
@@ -20,13 +20,4 @@ describe('asset loading tests', function() {
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.