I want to do some actions in a DOS batch file depending on the incoming command line parameters.
The batch shall be invoked with any number of parameters. Possible parameters shall be (in best case extendable):
UPDATE [-verbose [outputFileName]] [-validate] [/?]
Furthermore it should be possible to enter the params in any order.
Especially the param -verbose is of interest: If this parameter is given the following 'parameterParam' MUST be the name of the outputfilename or can be empty. Notice that the parameters have a leading "-". A parameter of a parameter argument has no leading "-".
For example:
UPDATE -verbose -validate
shall display execution steps on STDOUT (-verbose) and validate the input.
UPDATE -verbose outputFileName.txt -validate
shall log execution steps into a file named <outputFilename.txt> (-verbose outputFileName.txt) and validate the input.
UPDATE -validate
shall only validate the input.
UPDATE -validate -verbose
shall do the same as
UPDATE -verbose -validate
.
UPDATE /?
shall display how to use update.bat
How can I do that? Iterating over the command line arguments with a FOR loop? But how? I am able to iterate over the arguments but if -verbose is found how can I preview the following parameter to check if a filename is supplied?
According to the supplied parameter a specific action should take place (starting a different batch...) I want to invoke LiquiBase via java:
For validation:
java -jar %LIQUIBASE_EXEC% --changeLogFile=../changesets/changelog-update.xml --logLevel=info validate
java -jar %LIQUIBASE_EXEC% --changeLogFile=../changesets/changelog-views-and-sp.xml --logLevel=info validate
For offline SQL generation:
java -jar %LIQUIBASE_EXEC% --changeLogFile=../changesets/changelog-update.xml --logLevel=info updateSQL > update_%_outputfilename%
java -jar %LIQUIBASE_EXEC% --changeLogFile=../changesets/changelog-views-and-sp.xml --logLevel=info updateSQL > viewsAndSP_%_outputfilename%