All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.jbang.cli.TemplatePropertyConverter Maven / Gradle / Ivy

There is a newer version: 0.121.0
Show newest version
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; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy