Class EnvironmentArgumentsParser

java.lang.Object
com.bakdata.kafka.EnvironmentArgumentsParser

public class EnvironmentArgumentsParser extends Object

This class is primarily used to inject environment variables to the passed in command line arguments in KafkaPropertiesFactory.

In general a usage would look like this:


 final String[] environmentArguments = new EnvironmentArgumentsParser(ENV_PREFIX).parseVariables(System.getenv());
 
The class collects all environment variables starting with environmentPrefix and replaces the environmentDelimiter with the commandLineDelimiter. Furthermore, it transforms all words to lowercase and prepends "--" to match the command line argument descriptors.

Example:

var ENV_PREFIX = "APP_"; Transformation: APP_INPUT_TOPIC --> --input-topic
  • Constructor Details

    • EnvironmentArgumentsParser

      public EnvironmentArgumentsParser(String environmentPrefix)
      Create a new parser with a default command line delimiter of - and a default environment delimiter of _
      Parameters:
      environmentPrefix - prefix to use to detect environment variables representing a command line argument
    • EnvironmentArgumentsParser

      public EnvironmentArgumentsParser(String environmentPrefix, String commandLineDelimiter, String environmentDelimiter)
      Create a new parser
      Parameters:
      environmentPrefix - prefix to use to detect environment variables representing a command line argument
      commandLineDelimiter - delimiter to use to concatenate fragments of a command line argument
      environmentDelimiter - delimiter to use to detect fragments of a command line argument in an environment variable
  • Method Details

    • parseVariables

      public List<String> parseVariables(Map<String,String> environment)
      Parse a list of environment variables as command line arguments. All variables starting with the configured prefix are converted by using the configured delimiters.
      Parameters:
      environment - map of environment variables
      Returns:
      parsed command line arguments