new option --data-named (then follows name/value pairs without prefix/suffix) v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 24 Dec 2013 12:05:05 +0100
branchv_0
changeset 52e2ba2af0ef40
parent 51 6730214fab41
child 53 eb30ad93ca8b
new option --data-named (then follows name/value pairs without prefix/suffix)
java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java
java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java	Tue Dec 24 11:54:58 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java	Tue Dec 24 12:05:05 2013 +0100
     1.3 @@ -85,29 +85,29 @@
     1.4  				case Tokens.DATA: // --data is the last option
     1.5  					for (i++; i < args.length; i++) {
     1.6  						arg = args[i];
     1.7 -
     1.8 -						if (arg.startsWith(options.getNamePrefix()) && arg.endsWith(options.getNameSuffix())) { // Named parameters:
     1.9 -							String paramName = arg.substring(options.getNamePrefix().length(), arg.length() - options.getNameSuffix().length());
    1.10 -							String paramValue = fetchNext(args, ++i);
    1.11 -							options.addNamedParameter(new NamedParameter(paramName, paramValue, namedTypes.get(paramName)));
    1.12 -						} else { // Numbered parameters:
    1.13 -							Parameter parameter;
    1.14 -							if (numberedTypes.isEmpty()) {
    1.15 -								parameter = new Parameter(arg, null);
    1.16 -							} else {
    1.17 -								int paramIndex = options.getNumberedParameters().size();
    1.18 -								int paramType;
    1.19 -								try {
    1.20 -									paramType = numberedTypes.get(paramIndex);
    1.21 -								} catch (IndexOutOfBoundsException e) {
    1.22 -									throw new CLIParserException("Missing type for parameter #" + paramIndex, e);
    1.23 -								} catch (NullPointerException e) {
    1.24 -									throw new CLIParserException("Invalid type definition for parameter #" + paramIndex, e);
    1.25 -								}
    1.26 -								parameter = new Parameter(arg, paramType);
    1.27 +						Parameter parameter;
    1.28 +						if (numberedTypes.isEmpty()) {
    1.29 +							parameter = new Parameter(arg, null);
    1.30 +						} else {
    1.31 +							int paramIndex = options.getNumberedParameters().size();
    1.32 +							int paramType;
    1.33 +							try {
    1.34 +								paramType = numberedTypes.get(paramIndex);
    1.35 +							} catch (IndexOutOfBoundsException e) {
    1.36 +								throw new CLIParserException("Missing type for parameter #" + paramIndex, e);
    1.37 +							} catch (NullPointerException e) {
    1.38 +								throw new CLIParserException("Invalid type definition for parameter #" + paramIndex, e);
    1.39  							}
    1.40 -							options.addNumberedParameter(parameter);
    1.41 +							parameter = new Parameter(arg, paramType);
    1.42  						}
    1.43 +						options.addNumberedParameter(parameter);
    1.44 +					}
    1.45 +					break;
    1.46 +				case Tokens.DATA_NAMED:
    1.47 +					for (i++; i < args.length; i++) {
    1.48 +						String paramName = args[i];
    1.49 +						String paramValue = fetchNext(args, ++i);
    1.50 +						options.addNamedParameter(new NamedParameter(paramName, paramValue, namedTypes.get(paramName)));
    1.51  					}
    1.52  					break;
    1.53  				case Tokens.FORMATTER:
    1.54 @@ -156,6 +156,7 @@
    1.55  		public static final String SQL = "--sql";
    1.56  		public static final String BATCH = "--batch";
    1.57  		public static final String DATA = "--data";
    1.58 +		public static final String DATA_NAMED = "--data-named";
    1.59  		public static final String NAME_PREFIX = "--name-prefix";
    1.60  		public static final String NAME_SUFFIX = "--name-suffix";
    1.61  		public static final String TYPES = "--types";
     2.1 --- a/java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java	Tue Dec 24 11:54:58 2013 +0100
     2.2 +++ b/java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java	Tue Dec 24 12:05:05 2013 +0100
     2.3 @@ -19,7 +19,6 @@
     2.4  
     2.5  import info.globalcode.sql.dk.CLIParser.Tokens;
     2.6  import static info.globalcode.sql.dk.CLIParser.TYPE_NAME_SEPARATOR;
     2.7 -import static info.globalcode.sql.dk.CLIOptions.DEFAULT_NAME_PREFIX;
     2.8  import java.sql.Types;
     2.9  import java.util.Collection;
    2.10  import static org.testng.Assert.*;
    2.11 @@ -110,7 +109,7 @@
    2.12  		String[] args = new String[]{
    2.13  			Tokens.DB, DATABASE_NAME_1,
    2.14  			Tokens.SQL, SQL_1,
    2.15 -			Tokens.DATA, DEFAULT_NAME_PREFIX + NAME_1, DATA_1, DEFAULT_NAME_PREFIX + NAME_2, DATA_2, DEFAULT_NAME_PREFIX + NAME_3, DATA_3};
    2.16 +			Tokens.DATA_NAMED, NAME_1, DATA_1, NAME_2, DATA_2, NAME_3, DATA_3};
    2.17  		CLIOptions options = parser.parseOptions(args);
    2.18  		options.validate();
    2.19  
    2.20 @@ -130,7 +129,7 @@
    2.21  			Tokens.SQL, SQL_1,
    2.22  			Tokens.NAME_PREFIX, "$",
    2.23  			Tokens.TYPES, " " + NAME_1 + TYPE_NAME_SEPARATOR + "int" + "," + NAME_3 + TYPE_NAME_SEPARATOR + "boolean",
    2.24 -			Tokens.DATA, "$" + NAME_1, DATA_1, "$" + NAME_2, DATA_2, "$" + NAME_3, DATA_3};
    2.25 +			Tokens.DATA_NAMED, NAME_1, DATA_1, NAME_2, DATA_2, NAME_3, DATA_3};
    2.26  		CLIOptions options = parser.parseOptions(args);
    2.27  		options.validate();
    2.28