Skip to content

Commit 87beb6f

Browse files
Fatme HavaluovaFatme Havaluova
authored andcommitted
Execute the command only if the file exists
1 parent 6f91fc4 commit 87beb6f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/command-executor.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"use strict";
33

44
import Future = require("fibers/future");
5+
import fs = require("fs");
6+
import path = require("path");
57
import util = require("util");
68
require("colors");
79

@@ -20,12 +22,16 @@ export class CommandExecutor implements ICommandExecutor {
2022
private executeCore(commandName: string, commandArguments: string[]): IFuture<void> {
2123
return (() => {
2224
try {
23-
var command: ICommand = new (require("./commands/" + commandName).Command)();
24-
if(!command) {
25-
errors.fail("Unable to resolve commandName %s", commandName);
25+
let filePath = path.join(__dirname, "commands", commandName + ".js");
26+
if(fs.existsSync(filePath)) {
27+
var command: ICommand = new (require(filePath).Command)();
28+
if(!command) {
29+
errors.fail("Unable to resolve commandName %s", commandName);
30+
}
31+
32+
command.execute(commandArguments).wait();
2633
}
2734

28-
command.execute(commandArguments).wait();
2935
} catch(e) {
3036
if(options.debug) {
3137
throw e;

0 commit comments

Comments
 (0)