Recognize parameter separator for grape define command

This commit is contained in:
wang--ge 2024-03-14 14:39:03 +08:00
parent b40fade1e3
commit 671af8f569
2 changed files with 27 additions and 1 deletions

View File

@ -486,6 +486,29 @@ index fd9765c..db29526 100644
grapeHelp = {
int spacesLen = commands.keySet().max {it.length()}.length() + 3
@@ -326,10 +326,18 @@ if (cmd.hasOption('v')) {
return
}
-
-cmd.getOptionValues('D')?.each {String prop ->
- def (k, v) = prop.split ('=', 2) as List // array multiple assignment quirk
- System.setProperty(k, v ?: "")
+if (cmd.hasOption('D')) {
+ cmd.getOptionValues('D')?.each {String prop ->
+ while (prop.startsWith("=")) {
+ prop = prop.substring(1, prop.length());
+ }
+ def (k, v) = prop.split ('=', 2) as List // array multiple assignment quirk
+ if (k.isEmpty() || v.isEmpty()) {
+ println "one system property's name or value is emply, skip."
+ } else {
+ System.setProperty(k, v ?: "")
+ }
+ }
}
String[] arg = cmd.args
diff --git a/src/test/groovy/util/CliBuilderTest.groovy b/src/test/groovy/util/CliBuilderTest.groovy
index cbd7bd1..d67de50 100644
--- a/src/test/groovy/util/CliBuilderTest.groovy

View File

@ -2,7 +2,7 @@
%global archiver 1_8_9
Name: groovy18
Version: 1.8.9
Release: 3
Release: 4
Summary: Dynamic language for the Java Platform
License: ASL 2.0 and BSD and EPL-1.0 and Public Domain and CPL-1.0
URL: http://groovy-lang.org
@ -122,6 +122,9 @@ install -p -m644 %{SOURCE2} \
%license LICENSE.txt LICENSE-2.0.txt NOTICE.txt cpl-v10.txt epl-v10.txt
%changelog
* Mon Mar 11 2024 Ge Wang <wang__ge@126.com> - 1.8.9-4
- Add command line parser separator recogonition
* Mon Feb 26 2024 xu_ping <707078654@qq.com> - 1.8.9-3
- fix help information is consistent due to the singularity of the class method.