Packages

  • package root
    Definition Classes
    root
  • package args4c

    Args4c (arguments for configuration) is intended to add some helpers and utilities in obtaining a typesafe configuration from user arguments.

    Args4c (arguments for configuration) is intended to add some helpers and utilities in obtaining a typesafe configuration from user arguments.

    The core is simply to convert an Array[String] to a Config where the arguments are either paths to configuration resources or simple key=value pairs via args4c.configForArgs

    Left-most arguments take precedence. In this example, we assume 'prod.conf' is a resource on the classpath:

    MyApp foo.x=bar foo.x=ignored /opt/etc/overrides.conf prod.conf

    In addition to this core concept, this library also provides some additional configuration utilities via args4c.RichConfigOps which can be made available by extending args4c.LowPriorityArgs4cImplicits or importing args4c.implicits:

    import args4c.implicits._
    object MyApp {
       override def main(args : Array[String]) : Unit = {
         val config = args.asConfig()
         println("Starting MyApp with config:")
    
         // let's "log" our app's config on startup:
         config.filter(_.startsWith("myapp")).summary().foreach(println)
       }
    }

    Where the 'summary' will produce sorted args4c.StringEntry values with potentially sensitive entries (e.g. passwords) obscured and a source comment for some sanity as to where each entry comes from:

    myapp.foo : bar # command-line
    myapp.password : **** obscured **** # command-line
    myapp.saveTo : afile # file:/opt/etc/myapp/test.conf@3

    Also, when extracting user arguments into a configuration, an additional 'fallback' config is specified. Typically this would just be the ConfigFactory.load() configuration, but args4c uses the args4c.defaultConfig, which is essentially just the system environment variables converted from snake-caes to dotted lowercase values first, then falling back on ConfigFactory.load().

    Applications can elect to not have this behaviour and provide their own fallback configs when parsing args, but the default provides a convenience for system environment variables to override e.g. 'foo.bar.x=default' by specifying

    FOO_BAR_X=override

    as a system environment variable. Otherwise you may end up having to repeat this sort of thing all over you config:

    foo.bar=default
    foo.bar=$${?FOO_BAR}
    
    foo.bazz=default2
    foo.bazz=$${?FOO_BAZZ}
    
    ...

    Finally, args4c also provides a args4c.ConfigApp which provides some additional functionality to configuration-based applications.

    Definition Classes
    root
  • ConfigApp
  • Encryption
  • LowPriorityArgs4cImplicits
  • RichConfig
  • RichConfigOps
  • SecretConfig
  • StringEntry
  • implicits
t

args4c

RichConfigOps

trait RichConfigOps extends LowPriorityArgs4cImplicits

Provider operations on a 'config'

Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. RichConfigOps
  2. LowPriorityArgs4cImplicits
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. implicit class RichArgs extends AnyRef
    Definition Classes
    LowPriorityArgs4cImplicits
  2. implicit class RichString extends AnyRef
    Definition Classes
    LowPriorityArgs4cImplicits

Abstract Value Members

  1. abstract def config: Config

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def asDuration(key: String): Duration

    key

    the configuration path

    returns

    the value at the given key as a scala duration

  5. def asFiniteDuration(key: String): FiniteDuration
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def asJson: String

    returns

    the configuration as a json string

  8. def asList(path: String, separator: Option[String] = Option(",")): List[String]

    produces a scala list, either from a StringList or a comma-separated string value

    produces a scala list, either from a StringList or a comma-separated string value

    path

    the config path

    separator

    if specified, the value at the given path will be parsed if it is a string and not a stringlist

  9. implicit def asRichConfig(c: Config): RichConfig
    Definition Classes
    LowPriorityArgs4cImplicits
  10. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  11. def collectAsMap: Map[String, String]

    returns

    the configuration as a map

  12. def collectAsStrings: List[(String, String)]

    returns

    the configuration as a set of key/value tuples

  13. def encrypt(password: Array[Byte]): Array[Byte]

    returns

    the encrypted configuration

  14. def entries: Set[Entry[String, ConfigValue]]

    returns

    the configuration entries as a set of entries

  15. def entryPairs: Set[(String, ConfigValue)]

    returns

    the configuration entries as a set of entry tuples

  16. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  18. def filter(path: (String) ⇒ Boolean): Config
  19. def filterNot(path: (String) ⇒ Boolean): Config
  20. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  21. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  22. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  23. def intersect(other: Config): Config

    returns

    the configuration representing the intersection of the two configuration entries

  24. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  25. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  26. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  27. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  28. def origins: List[String]

    returns

    a sorted list of the origins from when the config values come

  29. def pathRoots: List[String]

    The available config roots.

    The available config roots.

    e.g. of a config has

    foo.bar.x = 1
    java.home = /etc/java
    bar.enabled = true
    bar.user = root

    The 'pathRoots' would return a [bar, foo, java]

    returns

    a sorted list of the root entries to the config.

  30. def paths: List[String]

    returns

    all the unique paths for this configuration

  31. def showIfSpecified(obscure: (String, String) ⇒ String = obscurePassword(_, _)): Option[String]

    If 'show=X' is specified, configuration values which contain X in their path will be displayed with the values matching 'obscure' obscured.

    If 'show=X' is specified, configuration values which contain X in their path will be displayed with the values matching 'obscure' obscured.

    If 'X' is 'all' or 'root', then the entire configuration is rendered.

    This can be useful to debug other command-line args (to ensure they take the desired effect) or to validate the environment variable replacement

    obscure

    a function which takes a dotted configuration path and string value and returns the value to display

    returns

    the optional value of what's pointed to if 'show=<path>' is specified

  32. def summary(obscure: (String, String) ⇒ String = obscurePassword(_, _)): String

    Return a property-like summary of the config using the pathFilter to trim property entries

    Return a property-like summary of the config using the pathFilter to trim property entries

    obscure

    a function which will 'safely' replace any config values with an obscured value

    returns

    a summary of the configuration

  33. def summaryEntries(obscure: (String, String) ⇒ String = obscurePassword(_, _)): List[StringEntry]

    Return a property-like summary of the config using the 'obscure' function to mask sensitive entries

    Return a property-like summary of the config using the 'obscure' function to mask sensitive entries

    obscure

    a function which will 'safely' replace any config values with an obscured value

  34. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  35. def toMap: Map[String, ConfigValue]

    returns

    the config as a map

  36. def toString(): String
    Definition Classes
    AnyRef → Any
  37. def uniquePaths: List[String]

    And example which uses most of the below stuff to showcase what this is for Note : writing a 'diff' using this would be pretty straight forward

  38. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  39. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  40. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  41. def withPaths(paths: List[String]): Config

    returns

    this configuration which only contains the specified paths

  42. def withPaths(first: String, theRest: String*): Config

    first

    the first path to include (keep)

    theRest

    any other paths to keep

    returns

    this configuration which only contains the specified paths

  43. def withUserArgs(args: Array[String], unrecognizedArg: (String) ⇒ Config = ParseArg.Throw): Config

    Overlay the given arguments over this configuration, where the arguments are taken to be in the form:

    Overlay the given arguments over this configuration, where the arguments are taken to be in the form:

    $ the path to a configuration file, either on the classpath or file system $ a <key>=<value> pair where the key is a 'path.to.a.configuration.entry'

    args

    the user arguments in the form <key>=<value>, <filePath> or <fileOnTheClasspath>

    unrecognizedArg

    what to do with malformed user input

    returns

    a configuration with the given user-argument overrides applied over top

  44. def without(configPaths: TraversableOnce[String]): Config
  45. def without(firstPath: String, theRest: String*): Config
  46. def without(other: Config): Config
  47. def withoutSystem: Config

    this config w/o the system properties or environment variables

Inherited from AnyRef

Inherited from Any

Ungrouped