Skip to content

Instantly share code, notes, and snippets.

@BrunoBonacci
Created July 1, 2012 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrunoBonacci/3028594 to your computer and use it in GitHub Desktop.
Save BrunoBonacci/3028594 to your computer and use it in GitHub Desktop.
Vert.x Simple Telnet Server - command handler
// 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