Created
July 1, 2012 14:29
-
-
Save BrunoBonacci/3028594 to your computer and use it in GitHub Desktop.
Vert.x Simple Telnet Server - command handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Regular expression to verify/extract pathnames from commands | |
PATH_ELEM = "[A-Za-z0-9.-]+" | |
PATH = "(/?$PATH_ELEM(/$PATH_ELEM)*/?|/)" | |
// Commands handler | |
bus.registerHandler("commands") { | |
msg -> | |
def cmd = msg.body.command | |
switch (cmd) { | |
case ~$/cd( $PATH)?/$: | |
def path = cmd.size() > 3 ? cmd[3..-1] : "" | |
msg.reply(cd(path, msg.body.cid)); | |
break; | |
case ~$/ls( $PATH)?/$: | |
def path = cmd.size() > 3 ? cmd[3..-1] : "" | |
msg.reply(ls(path, msg.body.cid)); | |
break; | |
case ~$/mkdir $PATH/$: | |
def path = cmd[6..-1] | |
msg.reply(mkdir(path, msg.body.cid)); | |
break; | |
case ~$/quit/$: | |
msg.reply([status: "ACTION", action: "QUIT", message: "Goodbye!!!"]); | |
break; | |
default: | |
msg.reply([status: "ERROR", message: "### ERROR: Sorry, this command is unrecognized!"]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment