matrei commented on code in PR #15397:
URL: https://github.com/apache/grails-core/pull/15397#discussion_r2817313089


##########
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:
   ```suggestion
           args.findAll { !it.startsWith('--') } as String[]
   ```



-- 
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]

Reply via email to