83 options.setBatch(true); |
83 options.setBatch(true); |
84 break; |
84 break; |
85 case Tokens.DATA: // --data is the last option |
85 case Tokens.DATA: // --data is the last option |
86 for (i++; i < args.length; i++) { |
86 for (i++; i < args.length; i++) { |
87 arg = args[i]; |
87 arg = args[i]; |
88 |
88 Parameter parameter; |
89 if (arg.startsWith(options.getNamePrefix()) && arg.endsWith(options.getNameSuffix())) { // Named parameters: |
89 if (numberedTypes.isEmpty()) { |
90 String paramName = arg.substring(options.getNamePrefix().length(), arg.length() - options.getNameSuffix().length()); |
90 parameter = new Parameter(arg, null); |
91 String paramValue = fetchNext(args, ++i); |
91 } else { |
92 options.addNamedParameter(new NamedParameter(paramName, paramValue, namedTypes.get(paramName))); |
92 int paramIndex = options.getNumberedParameters().size(); |
93 } else { // Numbered parameters: |
93 int paramType; |
94 Parameter parameter; |
94 try { |
95 if (numberedTypes.isEmpty()) { |
95 paramType = numberedTypes.get(paramIndex); |
96 parameter = new Parameter(arg, null); |
96 } catch (IndexOutOfBoundsException e) { |
97 } else { |
97 throw new CLIParserException("Missing type for parameter #" + paramIndex, e); |
98 int paramIndex = options.getNumberedParameters().size(); |
98 } catch (NullPointerException e) { |
99 int paramType; |
99 throw new CLIParserException("Invalid type definition for parameter #" + paramIndex, e); |
100 try { |
|
101 paramType = numberedTypes.get(paramIndex); |
|
102 } catch (IndexOutOfBoundsException e) { |
|
103 throw new CLIParserException("Missing type for parameter #" + paramIndex, e); |
|
104 } catch (NullPointerException e) { |
|
105 throw new CLIParserException("Invalid type definition for parameter #" + paramIndex, e); |
|
106 } |
|
107 parameter = new Parameter(arg, paramType); |
|
108 } |
100 } |
109 options.addNumberedParameter(parameter); |
101 parameter = new Parameter(arg, paramType); |
110 } |
102 } |
|
103 options.addNumberedParameter(parameter); |
|
104 } |
|
105 break; |
|
106 case Tokens.DATA_NAMED: |
|
107 for (i++; i < args.length; i++) { |
|
108 String paramName = args[i]; |
|
109 String paramValue = fetchNext(args, ++i); |
|
110 options.addNamedParameter(new NamedParameter(paramName, paramValue, namedTypes.get(paramName))); |
111 } |
111 } |
112 break; |
112 break; |
113 case Tokens.FORMATTER: |
113 case Tokens.FORMATTER: |
114 options.setFormatterName(fetchNext(args, ++i)); |
114 options.setFormatterName(fetchNext(args, ++i)); |
115 break; |
115 break; |
154 |
154 |
155 public static final String DB = "--db"; |
155 public static final String DB = "--db"; |
156 public static final String SQL = "--sql"; |
156 public static final String SQL = "--sql"; |
157 public static final String BATCH = "--batch"; |
157 public static final String BATCH = "--batch"; |
158 public static final String DATA = "--data"; |
158 public static final String DATA = "--data"; |
|
159 public static final String DATA_NAMED = "--data-named"; |
159 public static final String NAME_PREFIX = "--name-prefix"; |
160 public static final String NAME_PREFIX = "--name-prefix"; |
160 public static final String NAME_SUFFIX = "--name-suffix"; |
161 public static final String NAME_SUFFIX = "--name-suffix"; |
161 public static final String TYPES = "--types"; |
162 public static final String TYPES = "--types"; |
162 public static final String FORMATTER = "--formatter"; |
163 public static final String FORMATTER = "--formatter"; |
163 public static final String INFO_HELP = "--help"; |
164 public static final String INFO_HELP = "--help"; |