From f38010b397ee60f4cf3bb1c7316eb467d3dc6108 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 10 Aug 2015 21:15:15 +0200 Subject: Implement proper handling of unimplemented commands --- qml/CommandInput.qml | 2 +- qml/commands.js | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/qml/CommandInput.qml b/qml/CommandInput.qml index 5010891..ae48a7a 100644 --- a/qml/CommandInput.qml +++ b/qml/CommandInput.qml @@ -61,7 +61,7 @@ Item { break; } default: { - console.log('"' + prefix + '"' + " is not a command prefix"); + console.log('"' + prefix + '"' + " is not a command prefix."); } } diff --git a/qml/commands.js b/qml/commands.js index 9b4d8de..7d4bdcf 100644 --- a/qml/commands.js +++ b/qml/commands.js @@ -1,9 +1,21 @@ function execute(command) { + var msg = function(name) { + console.log('"' + name + '"' + " is not implemented."); + }; var args = command.split(' '); - var func = args[0]; - args.shift(); - eval(func + '(' + JSON.stringify(args) + ')'); + try { + var closure = eval(args[0]); + + if ( typeof closure === "function" ) { + args.shift(); + closure(args); + } else { + msg(args[0]); + } + } catch (exception) { + msg(args[0]); + } } function exec(args) { -- cgit v1.2.3