Allow overriding Spring Configuration Properties using PicoCLI-parsed arguments
AlexandreCassagne opened this issue · 2 comments
Is it possible, or would it be feasible to implement, the possibility to override spring properties using arguments parsed at command-line?
For instance, suppose you are creating a Spring API client, and the remote server is configurable using property myapp.apiRoot=https://example.com
, could we pass this as an argument mycommand --api-root https://example.com
?
Hi @AlexandreCassagne, FYI, @kakawait kindly contributed this module to the picocli project (https://github.com/remkop/picocli/tree/main/picocli-spring-boot-starter), so it may be good to raise this an an issue in the picocli project.
This issue (remkop/picocli#1378) looks like it may be related, but not exactly the same.
Also, the Spring Boot Example section in the picocli manual ends with a TIP on this topic:
It may be a good idea to define an option
--spring.config.location
in your command. Spring Boot allows end users to specify thespring.config.location
Spring environment property as a command line option to specify an alternative location for theapplication.properties
file. Defining this option prevents picocli from throwing an UnmatchedArgumentException ("Unknown option") when it sees an option it cannot match. You can make it a hidden option so it is not shown in the usage help message, or add a description that explains its meaning.
Alternatively, you can define an unmatched field to capture all unknown options (and positional parameters):
@Unmatched List<String> unmatched;
However, this is more of a workaround than a solution.
Would you mind opening a ticket on the picocli issue tracker to discuss further?
Closing in favour of remkop/picocli#1620