From cadeb9654c9f25f853c5bbdf9d3018d63925bdda Mon Sep 17 00:00:00 2001 From: Jermolene Date: Tue, 25 Feb 2014 14:50:18 +0000 Subject: [PATCH] Add help command --- core/modules/commands/help.js | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 core/modules/commands/help.js diff --git a/core/modules/commands/help.js b/core/modules/commands/help.js new file mode 100644 index 000000000..90c190829 --- /dev/null +++ b/core/modules/commands/help.js @@ -0,0 +1,41 @@ +/*\ +title: $:/core/modules/commands/help.js +type: application/javascript +module-type: command + +Help command + +\*/ +(function(){ + +/*jshint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.info = { + name: "help", + synchronous: true +}; + +var Command = function(params,commander) { + this.params = params; + this.commander = commander; +}; + +Command.prototype.execute = function() { + var subhelp = this.params[0] || "default", + helpBase = "$:/language/Help/", + text; + if(!this.commander.wiki.getTiddler(helpBase + subhelp)) { + subhelp = "notfound"; + } + // Wikify the help as formatted text (ie block elements generate newlines) + text = this.commander.wiki.renderTiddler("text/plain-formatted",helpBase + subhelp); + // Remove any leading linebreaks + text = text.replace(/^(\r?\n)*/g,""); + this.commander.streams.output.write(text); +}; + +exports.Command = Command; + +})();