-
Notifications
You must be signed in to change notification settings - Fork 440
Open
Labels
theme: compatibilityIssues related to binary and source backwards compatibilityIssues related to binary and source backwards compatibilitytype: API 🔌type: enhancement ✨
Milestone
Description
Hi,
I played around with the new PropertiesDefaultProvider implementation, I ended up with some code like:
package test;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;
import picocli.CommandLine.PropertiesDefaultProvider;
public class PropertiesDefaultProviderTest {
static {
System.setProperty("picocli.defaults.mycmd.path", "Prop.properties");
}
public static void main(String[] args) {
CommandLine cmd = new CommandLine(new MyCmd());
cmd.setDefaultValueProvider(new PropertiesDefaultProvider());
cmd.execute(args);
}
}
@Command(name="mycmd")
class MyCmd implements Runnable {
@Parameters(descriptionKey = "files")
String[] params = { "myFile1", "myFile2" };
@Override
public void run() {
for (String s : params)
System.out.println(s);
System.out.println(String.format("Number of files: %s", params.length));
}
}
If I run this with an empty properties file, I'm getting:
myFile1
myFile2
Number of files: 2
Now I'm putting a minimal properties file in place:
files=file1 file2
Once the parameters are retrieved rom the properties file, the output now is:
file1 file2
Number of files: 1
Of course I can split up the string programmatically, but this is somehow inconvenient.
I remember that when localizing the app, there is a very elegant way to specify multiple lines, like:
usage.description.0 = first line
usage.description.1 = second line
usage.description.2 = third line
Having that in mind, I tried:
files.0=file1
files.1=file2
This didn't do the trick, however.
Is this something that can be implemented? The proposed addition would make the new PropertiesDefaultProvider even better and more helpful IMHO.
Metadata
Metadata
Assignees
Labels
theme: compatibilityIssues related to binary and source backwards compatibilityIssues related to binary and source backwards compatibilitytype: API 🔌type: enhancement ✨