T
Torrey Slattery
I'm working on a program that takes user input via command line, then
calls whatever method is related to that input text.
For instance, if they type /help it calls the method help, if they type
/quit it calls the method quit, /time calls time, etc.
Essentially, if they type in something with a slash, I want the program
to interpret it as a special command, strip off the / and calls a method
with the leftover text.
I can think of a clunky way to do this using a ton of if/elsif clauses
and matching regular expressions, but as I eventually plan to have over
a hundred commands, that doesn't seem pleasant to write at all.
Is there a cleaner way to do this?
calls whatever method is related to that input text.
For instance, if they type /help it calls the method help, if they type
/quit it calls the method quit, /time calls time, etc.
Essentially, if they type in something with a slash, I want the program
to interpret it as a special command, strip off the / and calls a method
with the leftover text.
I can think of a clunky way to do this using a ton of if/elsif clauses
and matching regular expressions, but as I eventually plan to have over
a hundred commands, that doesn't seem pleasant to write at all.
Is there a cleaner way to do this?