I am working on a command line utility that takes set of input parameters as command. Those input parameters are then validated against predefined names. The utility is invoked in this manner:
runUtility.cmd -A -B x,y,z -C w
Here parameters are A, B and C (one that starts with -). Now the validation rules are as follows:
Parameter's name should match predefined names, so that one can not pass any invalid parameter say -UVW
Parameter may or may not have a value. In above example -A has no value, while -B has x,y,z and -C has w.
I have written this code to validate the inputs:
:validate
set argument=%1
set argumentValue=%2
if "%argument%" == "-A" (
shift
goto validate
)
if "%argument%" == "-B" (
if "%argumentValue%" == "" (
echo Empty value for -B
goto end
)
shift
shift
goto validate
)
if "%argument%" == "-C" (
if "%argumentValue%" == "" (
echo Empty value for -C
goto end
)
shift
shift
goto validate
)
if %argument%" == "" (
goto end
)
Argument %argument% is invalid
:end
But this does not seem to work, as -B has comma separated values, so for B when it does two shifts, in the next iteration, y becomes %1 and z becomes %2. Since y is not a parameter, it fails with last line of code that "Argument y is invalid". Actually comma is taken as delimiter by SHIFT command, so x,y,z does remain a single value.
I want x,y,z to be taken as a single value OR is there any other way to process this? I am bit new to batch scripting , I tried with FOR loop but there I was not able to get %1 and %2 together in every iteration.