jamesfredley commented on code in PR #15397:
URL: https://github.com/apache/grails-core/pull/15397#discussion_r2824200043
##########
grails-console/src/main/groovy/grails/ui/command/GrailsApplicationContextCommandRunner.groovy:
##########
@@ -85,6 +97,32 @@ class GrailsApplicationContextCommandRunner extends
DevelopmentGrailsApplication
return null
}
+ /**
+ * Filters out command-specific options (arguments starting with '--')
from the
+ * args array before they are passed to Spring Boot's {@code
SpringApplication.run()}.
+ *
+ * <p>Spring Boot interprets {@code --key=value} arguments as property
overrides via
+ * {@code CommandLinePropertySource}. When Grails command options like
+ * {@code --dataSource=analytics} are passed through, Spring Boot sets
+ * {@code dataSource=analytics} as a top-level property, corrupting GORM's
datasource
+ * configuration which expects {@code dataSource} to be a Map containing
url, username, etc.</p>
+ *
+ * <p>Command options are still available to the Grails command via
+ * {@code CommandLineParser.parse(args)} which receives the unfiltered
args.</p>
+ *
+ * @param args the full argument array including command options
+ * @return a filtered array with command options removed, safe for Spring
Boot
+ */
+ static String[] filterCommandOptions(String[] args) {
+ List<String> filtered = new ArrayList<>()
+ for (String arg : args) {
+ if (!arg.startsWith('--')) {
+ filtered.add(arg)
+ }
+ }
+ filtered.toArray(new String[0])
+ }
Review Comment:
No change needed. Filtering bare `--` is correct behavior here.
Grails commands do not use the POSIX `--` end-of-options delimiter
convention. The args are parsed by `CommandLineParser.parse(args)` which is a
custom Grails parser with its own semantics. Additionally, Spring Boot's
`SimpleCommandLineArgsParser` also treats bare `--` specially (as an empty
property name), so filtering it out before reaching Spring Boot is the right
thing to do. No Grails user would pass a bare `--` as a meaningful command
argument.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]