Class SbkUtils

java.lang.Object
io.sbk.utils.SbkUtils

public final class SbkUtils extends Object
Utility methods for inspecting, filtering, and merging SBK arguments.
  • Constructor Details

    • SbkUtils

      public SbkUtils()
      Creates an SBK argument utility.
  • Method Details

    • redactOptionValues

      @NotNull public static @NotNull String[] redactOptionValues(String[] args, String[] sensitiveOptions)
      Return a copy of command-line arguments with values belonging to sensitive options replaced by a fixed mask. Both -option value and --option=value forms are supported, without modifying the source array.
      Parameters:
      args - command-line arguments
      sensitiveOptions - sensitive option names, with or without leading dashes
      Returns:
      copied arguments with sensitive values redacted
    • redactSensitiveOptionValues

      @NotNull public static @NotNull String[] redactSensitiveOptionValues(String[] args)
      Return a copy of SBK arguments with values for commonly used credential options replaced by a fixed mask.
      Parameters:
      args - command-line arguments
      Returns:
      copied arguments with credential values redacted
    • removeOptionArgsAndValues

      @Contract("null, _ -> new") @NotNull public static @NotNull String[] removeOptionArgsAndValues(String[] args, String[] opts)
      Removes each named option and its following value once.
      Parameters:
      args - source arguments
      opts - option names to remove
      Returns:
      filtered arguments
    • removeOptionArgs

      @Contract("null, _ -> new") @NotNull public static @NotNull String[] removeOptionArgs(String[] args, String[] opts)
      Removes each named option once while retaining other arguments.
      Parameters:
      args - source arguments
      opts - option names to remove
      Returns:
      filtered arguments
    • getArgValue

      public static String getArgValue(String[] args, String argName)
      Finds the value following an option.
      Parameters:
      args - source arguments
      argName - option name
      Returns:
      option value, or an empty string when absent
    • getClassName

      public static String getClassName(String[] args)
      Returns the selected storage class name.
      Parameters:
      args - source arguments
      Returns:
      storage class name, or an empty string when absent
    • getLoggerName

      public static String getLoggerName(String[] args)
      Returns the selected logger name.
      Parameters:
      args - source arguments
      Returns:
      logger name, or an empty string when absent
    • hasArg

      public static boolean hasArg(String[] args, String argName)
      Tests whether an argument is present.
      Parameters:
      args - source arguments
      argName - argument to find
      Returns:
      true when present
    • hasHelp

      public static boolean hasHelp(String[] args)
      Tests whether the help option is present.
      Parameters:
      args - source arguments
      Returns:
      true when help was requested
    • hasVersion

      public static boolean hasVersion(String[] args)
      Tests whether either version option is present.
      Parameters:
      args - source arguments
      Returns:
      true when version information was requested
    • mapToArgs

      public static String[] mapToArgs(Map<String,String> map, boolean addArgPrefix)
      Converts ordered option/value mappings to an argument array.
      Parameters:
      map - option/value mappings
      addArgPrefix - whether to prepend the standard argument prefix
      Returns:
      argument array
    • argsToMap

      public static Map<String,String> argsToMap(String[] args, boolean removeArgPrefix)
      Converts option/value argument pairs to an ordered map.
      Parameters:
      args - option/value argument pairs
      removeArgPrefix - whether to remove the standard argument prefix
      Returns:
      ordered option/value mappings
    • mergeArgs

      public static String[] mergeArgs(String[] s1, String[] s2)
      Merges two option/value arrays, with the second array taking precedence.
      Parameters:
      s1 - base arguments
      s2 - overriding arguments
      Returns:
      merged argument array without duplicate options