From 9410216b027e69d8d954125adb4c2fce7372afca Mon Sep 17 00:00:00 2001 From: Marko Schulz Date: Tue, 3 Jun 2014 22:50:25 +0200 Subject: [PATCH] Make getCommandId() more readable. --- lib/coffee-script/repl.js | 10 +++++----- src/repl.coffee | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/coffee-script/repl.js b/lib/coffee-script/repl.js index 7c0869a6..e2251d23 100644 --- a/lib/coffee-script/repl.js +++ b/lib/coffee-script/repl.js @@ -125,7 +125,7 @@ repl.rli.on('exit', function() { return fs.close(fd); }); - return repl.commands[getCommandId(repl, '.history')] = { + return repl.commands[getCommandId(repl, 'history')] = { help: 'Show command history', action: function() { repl.outputStream.write("" + (repl.rli.history.slice(0).reverse().join('\n')) + "\n"); @@ -136,11 +136,11 @@ getCommandId = function(repl, commandName) { var commandsHaveLeadingDot; - commandsHaveLeadingDot = !repl.commands['help']; + commandsHaveLeadingDot = repl.commands['.help'] != null; if (commandsHaveLeadingDot) { - return commandName; + return "." + commandName; } else { - return commandName.slice(1); + return commandName; } }; @@ -168,7 +168,7 @@ if (opts.historyFile) { addHistory(repl, opts.historyFile, opts.historyMaxInputSize); } - repl.commands[getCommandId(repl, '.load')].help = 'Load code from a file into this REPL session'; + repl.commands[getCommandId(repl, 'load')].help = 'Load code from a file into this REPL session'; return repl; } }; diff --git a/src/repl.coffee b/src/repl.coffee index e15b424d..a7445852 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -120,7 +120,7 @@ addHistory = (repl, filename, maxSize) -> repl.rli.on 'exit', -> fs.close fd # Add a command to show the history stack - repl.commands[getCommandId(repl, '.history')] = + repl.commands[getCommandId(repl, 'history')] = help: 'Show command history' action: -> repl.outputStream.write "#{repl.rli.history[..].reverse().join '\n'}\n" @@ -128,8 +128,8 @@ addHistory = (repl, filename, maxSize) -> getCommandId = (repl, commandName) -> # Node 0.11 changed API, a command such as '.help' is now stored as 'help' - commandsHaveLeadingDot = ! repl.commands['help'] - if commandsHaveLeadingDot then commandName else commandName[1..] + commandsHaveLeadingDot = repl.commands['.help']? + if commandsHaveLeadingDot then ".#{commandName}" else commandName module.exports = start: (opts = {}) -> @@ -147,5 +147,5 @@ module.exports = addMultilineHandler repl addHistory repl, opts.historyFile, opts.historyMaxInputSize if opts.historyFile # Adapt help inherited from the node REPL - repl.commands[getCommandId(repl, '.load')].help = 'Load code from a file into this REPL session' + repl.commands[getCommandId(repl, 'load')].help = 'Load code from a file into this REPL session' repl