From ce8f86e58741b3151977b4af5045542a67ad499d Mon Sep 17 00:00:00 2001 From: Joe Walker Date: Mon, 13 Dec 2010 15:32:23 +0000 Subject: [PATCH] fix help command --- plugins/pilot/lib/commands/basic.js | 77 ++++++++++++++--------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/plugins/pilot/lib/commands/basic.js b/plugins/pilot/lib/commands/basic.js index ae2bc01c..ae16a47e 100644 --- a/plugins/pilot/lib/commands/basic.js +++ b/plugins/pilot/lib/commands/basic.js @@ -39,71 +39,67 @@ define(function(require, exports, module) { var util = require('pilot/util'); +var canon = require('pilot/canon'); /** * 'help' command */ var helpCommandSpec = { - name: "help", + name: 'help', params: [ { - name: "search", - type: "text", - description: "Search string to narrow the output.", + name: 'search', + type: 'text', + description: 'Search string to narrow the output.', defaultValue: null } ], - description: "Get help on the available commands.", + description: 'Get help on the available commands.', exec: function(env, args, request) { var output = []; - var command = catalog.getExtensionByKey('command', args.search); - if (command && command.pointer) { + var command = canon.getCommand(args.search); + if (command && command.exec) { // caught a real command - output.push(command.description); + output.push(command.description ? + command.description : + 'No description for ' + args.search); } else { var showHidden = false; if (!args.search) { output.push('

Welcome to Skywriter - Code in the Cloud

"); + '
  • Home Page
  • ' + + '
  • Wiki
  • ' + + '
  • User Guide
  • ' + + '
  • Tips and Tricks
  • ' + + '
  • FAQ
  • ' + + '
  • Developers Guide
  • ' + + ''); } if (command) { // We must be looking at sub-commands output.push('

    Sub-Commands of ' + command.name + '

    '); output.push('

    ' + command.description + '

    '); - } else if (args.search) { + } + else if (args.search) { if (args.search == 'hidden') { // sneaky, sneaky. args.search = ''; showHidden = true; } output.push('

    Commands starting with \'' + args.search + '\':

    '); - } else { + } + else { output.push('

    Available Commands:

    '); } - var toBeSorted = []; - catalog.getExtensions('command').forEach(function(command) { - toBeSorted.push(command.name); - }); - - var sorted = toBeSorted.sort(); + var commandNames = canon.getCommandNames(); + commandNames.sort(); output.push(''); - for (var i = 0; i < sorted.length; i++) { - command = catalog.getExtensionByKey('command', sorted[i]); - if (!command) { - console.error('Huh? command ', command.name, ' cannot be looked up by name'); - continue; - } - + for (var i = 0; i < commandNames.length; i++) { + command = canon.getCommand(commandNames[i]); if (!showHidden && command.hidden) { continue; } @@ -134,7 +130,7 @@ var helpCommandSpec = { output.push('
    '); if (!args.search) { - output.push("For more information, see the Skywriter Wiki."); + output.push('For more information, see the Skywriter Wiki.'); } } @@ -146,15 +142,15 @@ var helpCommandSpec = { * 'eval' command */ var evalCommandSpec = { - name: "eval", + name: 'eval', params: [ { - name: "javascript", - type: "text", - description: "The JavaScript to evaluate" + name: 'javascript', + type: 'text', + description: 'The JavaScript to evaluate' } ], - description: "evals given js code and show the result", + description: 'evals given js code and show the result', hidden: true, exec: function(env, args, request) { var result; @@ -210,7 +206,7 @@ var evalCommandSpec = { type = typeof result; } - request.done('Result for eval "' + javascript + '"' + + request.done('Result for eval \'' + javascript + '\'' + ' (type: '+ type+'):

    '+ msg); } }; @@ -219,8 +215,8 @@ var evalCommandSpec = { * 'version' command */ var versionCommandSpec = { - name: "version", - description: "show the Skywriter version", + name: 'version', + description: 'show the Skywriter version', hidden: true, exec: function(env, args, request) { var version = 'Skywriter ' + skywriter.versionNumber + ' (' + @@ -233,8 +229,7 @@ var versionCommandSpec = { * 'skywriter' command */ var skywriterCommandSpec = { - name: "skywriter", - description: "has", + name: 'skywriter', hidden: true, exec: function(env, args, request) { var index = Math.floor(Math.random() * messages.length);