@@ -153,18 +153,17 @@ private static Options buildOptions() {
153
153
.withLongOpt ("transformer-factory" )
154
154
.create ('t' ));
155
155
options .addOption (OptionBuilder
156
- .hasOptionalArg ()
156
+ .hasArg ()
157
157
.withArgName ("pattern" )
158
- .withDescription ("keep comments matching given pattern "
159
- + "or any pattern if pattern is omitted or empty" )
160
- .withLongOpt ("keep-comments" )
158
+ .withDescription ("use give pattern to match comments" )
159
+ .withLongOpt ("comment-pattern" )
161
160
.create ('c' ));
162
161
options .addOption (OptionBuilder
163
162
.hasArg ()
164
163
.withArgName ("flags" )
165
164
.withDescription ("flags following the specification of XPath "
166
- + "except for flag v (see NOTES below)" )
167
- .withLongOpt ("matching-flags" )
165
+ + "except for flag \" v \" (see NOTES below)" )
166
+ .withLongOpt ("comment- matching-flags" )
168
167
.create ('g' ));
169
168
options .addOption (OptionBuilder
170
169
.hasArg ()
@@ -182,12 +181,13 @@ private static Options buildOptions() {
182
181
private static void printUsage (Options options ) {
183
182
new HelpFormatter ().printHelp ("java -jar ruleml2tptp.jar" ,
184
183
null , options , String .format ("%nNOTES%n"
185
- + "If '-s' or '-o' is omitted, the standard input or "
186
- + "output will be used accordingly.%n"
187
- + "If '-h' is used, "
188
- + "no XML transformation will be performed.%n"
189
- + "Flag v means the matching behavior is reverted, "
190
- + "so comments DO NOT match the given pattern are kept. "
184
+ + "If '-s' or '-o' is omitted, the standard input or output will be used accordingly.%n"
185
+ + "If '-h' is used, no XML transformation will be performed.%n"
186
+ + "By default, all the comments in the source will be kept in the output. "
187
+ + "Use '-c' to switch to keep only those matching the given pattern. "
188
+ + "An empty pattern has no effect. "
189
+ + "Flag \" v\" reverts the behavior by keeping those not matching the pattern, "
190
+ + "or by ignoring all the comments if no or empty pattern is given."
191
191
),
192
192
true );
193
193
System .out .println ();
@@ -246,15 +246,19 @@ public void run(CommandLine cmd) throws FileNotFoundException, IOException,
246
246
new BufferedReader (new InputStreamReader (
247
247
xsltNormalizer ))));
248
248
} else {
249
+ // parse translator parameters
249
250
String commentPattern = cmd .getOptionValue ('c' );
250
- String matchingFlags = cmd .getOptionValue ('g' );
251
- if (matchingFlags == null ) {
252
- matchingFlags = "" ;
251
+ if (commentPattern == null ) {
252
+ commentPattern = "" ;
253
+ }
254
+ String commentMatchingFlags = cmd .getOptionValue ('g' );
255
+ if (commentMatchingFlags == null ) {
256
+ commentMatchingFlags = "" ;
253
257
}
254
- boolean keepComments = cmd .hasOption ('c' )
255
- && (matchingFlags .indexOf ('v' ) == -1 );
256
- matchingFlags = matchingFlags .replaceAll ("v" , "" );
258
+ boolean keepComments = (commentMatchingFlags .indexOf ('v' ) == -1 );
259
+ commentMatchingFlags = commentMatchingFlags .replaceAll ("v" , "" );
257
260
boolean useCrlf = cmd .hasOption ('r' );
261
+
258
262
Transformer translator = null ; // to set params
259
263
if (xsltNormalizer == null ) {
260
264
translator = tFactory .newTransformer (
@@ -273,14 +277,8 @@ public void run(CommandLine cmd) throws FileNotFoundException, IOException,
273
277
new BufferedReader (new InputStreamReader (
274
278
xsltNormalizer ))));
275
279
}
276
- if (commentPattern != null && !commentPattern .isEmpty ()) {
277
- translator .setParameter (
278
- "match-comments" , commentPattern );
279
- }
280
- if (!matchingFlags .isEmpty ()) {
281
- translator .setParameter (
282
- "matching-flags" , matchingFlags );
283
- }
280
+ translator .setParameter ("comment-pattern" , commentPattern );
281
+ translator .setParameter ("comment-matching-flags" , commentMatchingFlags );
284
282
translator .setParameter ("keep-comments" , keepComments );
285
283
translator .setParameter ("use-crlf" , useCrlf );
286
284
}
0 commit comments