dev.jbang.cli.TemplatePropertyConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbang-cli Show documentation
Show all versions of jbang-cli Show documentation
JBang Command Line Interface
package dev.jbang.cli;
import org.apache.commons.lang3.StringUtils;
import picocli.CommandLine.ITypeConverter;
/**
* Template property converter that is able to parse the following input:
*
*
* - property-name
* - property-name:property-description
* - property-name:property-description:default-value
* - property-name::default-value
*
*
* Examples:
*
* - test-key
* - "test-key:This is a description for the property"
* - "test-key:This is a description for the property:2.11"
* - "test-key::2.11"
*
*
*/
public class TemplatePropertyConverter implements ITypeConverter {
@Override
public TemplateAdd.TemplatePropertyInput convert(final String input) throws Exception {
String[] propertyParts = input.split(":");
TemplateAdd.TemplatePropertyInput templatePropertyInput = new TemplateAdd.TemplatePropertyInput();
if (propertyParts.length > 0 && StringUtils.isNotBlank(propertyParts[0])) {
templatePropertyInput.setKey(propertyParts[0]);
}
if (propertyParts.length > 1 && StringUtils.isNotBlank(propertyParts[1])) {
templatePropertyInput.setDescription(propertyParts[1]);
}
if (propertyParts.length > 2 && StringUtils.isNotBlank(propertyParts[2])) {
templatePropertyInput.setDefaultValue(propertyParts[2]);
}
return templatePropertyInput;
}
}