2024-05-03 10:57:46 +02:00
|
|
|
commit 77218790904f40395304669f5d79740f459c0a90 (HEAD -> cli-253, origin/cli-253)
|
|
|
|
Author: Michal Srb <msrb@redhat.com>
|
|
|
|
AuthorDate: Mon Jun 22 15:01:30 2015 +0200
|
|
|
|
Commit: Michal Srb <msrb@redhat.com>
|
|
|
|
CommitDate: Mon Jun 22 15:04:05 2015 +0200
|
|
|
|
|
|
|
|
[CLI-253] Prevent "Unrecognized option: --null" when handling long opts in PosixParser
|
|
|
|
|
2024-05-31 14:26:18 +02:00
|
|
|
Index: commons-cli-1.7.0-src/src/main/java/org/apache/commons/cli/Options.java
|
2024-05-03 10:57:46 +02:00
|
|
|
===================================================================
|
2024-05-31 14:26:18 +02:00
|
|
|
--- commons-cli-1.7.0-src.orig/src/main/java/org/apache/commons/cli/Options.java
|
|
|
|
+++ commons-cli-1.7.0-src/src/main/java/org/apache/commons/cli/Options.java
|
|
|
|
@@ -195,6 +195,20 @@ public class Options implements Serializ
|
2024-05-03 10:57:46 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ * Retrieve the {@link Option} matching the long name specified.
|
|
|
|
+ * The leading hyphens in the name are ignored (up to 2).
|
|
|
|
+ *
|
|
|
|
+ * @param opt long name of the {@link Option}
|
|
|
|
+ * @return the option represented by opt
|
|
|
|
+ */
|
|
|
|
+ Option getLongOption(String opt)
|
|
|
|
+ {
|
|
|
|
+ opt = Util.stripLeadingHyphens(opt);
|
|
|
|
+
|
|
|
|
+ return longOpts.get(opt);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Gets the options with a long name starting with the name specified.
|
|
|
|
*
|
2024-05-31 14:26:18 +02:00
|
|
|
Index: commons-cli-1.7.0-src/src/main/java/org/apache/commons/cli/PosixParser.java
|
2024-05-03 10:57:46 +02:00
|
|
|
===================================================================
|
2024-05-31 14:26:18 +02:00
|
|
|
--- commons-cli-1.7.0-src.orig/src/main/java/org/apache/commons/cli/PosixParser.java
|
|
|
|
+++ commons-cli-1.7.0-src/src/main/java/org/apache/commons/cli/PosixParser.java
|
2024-05-03 10:57:46 +02:00
|
|
|
@@ -145,7 +145,7 @@ public class PosixParser extends Parser
|
|
|
|
} else if (matchingOpts.size() > 1) {
|
|
|
|
throw new AmbiguousOptionException(opt, matchingOpts);
|
|
|
|
} else {
|
|
|
|
- currentOption = options.getOption(matchingOpts.get(0));
|
|
|
|
+ currentOption = options.getLongOption(matchingOpts.get(0));
|
|
|
|
|
|
|
|
tokens.add("--" + currentOption.getLongOpt());
|
|
|
|
if (pos != -1) {
|
2024-05-31 14:26:18 +02:00
|
|
|
Index: commons-cli-1.7.0-src/src/test/java/org/apache/commons/cli/bug/BugCLI253Test.java
|
2024-05-03 10:57:46 +02:00
|
|
|
===================================================================
|
|
|
|
--- /dev/null
|
2024-05-31 14:26:18 +02:00
|
|
|
+++ commons-cli-1.7.0-src/src/test/java/org/apache/commons/cli/bug/BugCLI253Test.java
|
2024-05-03 10:57:46 +02:00
|
|
|
@@ -0,0 +1,44 @@
|
|
|
|
+/*
|
|
|
|
+ * Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
+ * contributor license agreements. See the NOTICE file distributed with
|
|
|
|
+ * this work for additional information regarding copyright ownership.
|
|
|
|
+ * The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
+ * (the "License"); you may not use this file except in compliance with
|
|
|
|
+ * the License. You may obtain a copy of the License at
|
|
|
|
+ *
|
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
+ *
|
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
|
+ * limitations under the License.
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+package org.apache.commons.cli.bug;
|
|
|
|
+
|
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.cli.CommandLine;
|
|
|
|
+import org.apache.commons.cli.Option;
|
|
|
|
+import org.apache.commons.cli.Options;
|
|
|
|
+import org.apache.commons.cli.ParseException;
|
|
|
|
+import org.apache.commons.cli.PosixParser;
|
|
|
|
+import org.junit.Test;
|
|
|
|
+
|
|
|
|
+@SuppressWarnings("deprecation") // tests some deprecated classes
|
|
|
|
+public class BugCLI253Test {
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testGroovyUseCase() throws ParseException {
|
|
|
|
+ CommandLine cli = new PosixParser().parse(getOptions(), new String[] { "--classpath" });
|
|
|
|
+ assertTrue(cli.hasOption("--classpath"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Options getOptions() {
|
|
|
|
+ Options options = new Options();
|
|
|
|
+ options.addOption(Option.builder("classpath").build());
|
|
|
|
+ options.addOption(Option.builder("cp").longOpt("classpath").build());
|
|
|
|
+ return options;
|
|
|
|
+ }
|
|
|
|
+}
|