You can use a FOR /F to parse out the command from the arguments.
I would define a variable containing a delimited list of all valid commands. Then you can use simple search and replace to validate whether the user entered command is valid.
Addition of a new command is as easy as adding the command to the list, and creating a labeled subroutine for the new command.
I would use CALL instead of GOTO so that each routine can easily parse the arguments. The only disadvantage is CALL will double up quoted carets (
Here is a basic framework that can easily be extended. Note that user entered
! will be corrupted (or expanded) because of delayed expansion. There are simple ways to get around this limitation with additional code.
echo Simple command-line interface
:: Define all valid commands: make sure there is a space between each command
:: and also one at beginning and end
set "commands= something echo exit "
:: Clear the existing value in case user hits <Enter> without entering anything
:: Get the next command
set /p "input=COMMAND\>"
:: Parse command into command and arguments.
for /f "tokens=1* delims= " %%A in ("!input!") do (
REM check if command is valid (not case sensitive) and act accordingly
if "!commands: %%A =!" equ "!commands!" (
echo Invalid command: %%A
) else if /i %%A equ exit (
) else (
call :%%A %%B
echo Doing something with Arg1=[%1] and Arg2=[%2]