Git Product home page Git Product logo

configrity's Introduction

Configrity README file

Configrity is a configuration library for Scala 2.10 or +. Configuration instances are immutable, thread-safe and allow functional design patterns, such as:

  • Getting options to values
  • Converting implicitly values via type-classes
  • Reader monad

The API is stable and covered by tests.

Build Status

Example

import org.streum.configrity._

val config = Configuration.load( "server.conf" )

val hostname = config[String]("host")
val port = config[Int]("port")

val updatedConfig = config.set ("port",8080 )
upddatedConfig.save( "local.conf" )	

Features

Implemented

  • Automatic values conversions via type classes.
  • Loading configurations from any source (File, InputStream, URL, etc.)
  • Loading configurations from system properties and environment variables.
  • Saving configurations to files.
  • Interoperability with java properties.
  • Hierarchical configuration blocks.
  • Configuration chaining (such as to provide default values).
  • Single import: import org.streum.configrity._ imports all you need.
  • Access through reader monads
  • Values can be lists (v0.7.0)
  • Extra value converters: File, Color, URL, URI (v0.7.0)
  • include directive is supported, adding compatibility with Akka and Configgy configurations files.
  • Loading configurations from classpath/resources (v0.9.0)
  • YAML format support (v0.10.0)

Planned

  • More export/Import formats: INI, JSON, XML, apache, etc.
  • Build configurations from command line arguments

Requirements

Configrity depends on Scala 2.10 or newer.

While core features do not depend on external libraries, some modules may. In that case, the approriate dependencies will be automatically installed by sbt/maven.

Installation

From SBT

The dependency line is:

"org.streum" %% "configrity-core" % "1.0.0"

Additional modules require addition dependency lines. Check the wiki for more information: https://github.com/paradigmatic/Configrity/wiki/Modules

From Maven, Buildr, Ivy, Grape and Grails

Follow the repository instructions.

From source (master branch)

To install Configrity you just need a working java installation (tested with JDK 1.6 and 1.7, but may work with 1.5) and SBT 0.13.5:

$ git clone git://github.com/paradigmatic/Configrity.git
$ cd Configrity
$ sbt
> test
> doc
> package

Documentation

See the wiki: https://github.com/paradigmatic/Configrity/wiki

A scaladoc reference can be found online: http://paradigmatic.github.com/Configrity/

Collaboration

Reporting bugs and asking for features

You can github issues tracker, to report bugs or to ask for new features:

https://github.com/paradigmatic/Configrity/issues

Submitting patches

Patches are gladly accepted from their original author. Along with any patches, please state that the patch is your original work and that you license the work to the Configrity project under the LGPLv3 or a compatible license.

To propose a patch, fork the project and send a pull request via github. Tests are appreciated.

License and ownership

Configrity is a free and open source library released under the permissive GNU LesserGPLv3 license (see LICENSE.txt).

Copyright (C) 2011-2014. Paradigmatic. All rights reserved.

configrity's People

Contributors

gseitz avatar jvirtanen avatar lalloni avatar mkonicek avatar paradigmatic avatar purefn avatar triplem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

configrity's Issues

Bug when parsing files with whatespaces in path

Hey there,
Configrity seems to be throwing exceptions when parsing Files that contain whitespaces in the path. Is this a bug?

example of configuration:

managed {
  directories = [C:\Users\arg\Documents\RCT3,C:\Users\arg\Documents\StarCraft II\Accounts\662168\2-S2-1-821040\Replays\Multiplayer]
}

I should mention that the configuration file is generated by the library itself.

we have here a list of files, this error is thrown:

org.streum.configrity.io.StandardFormat$ParserException: [2.79] failure: `]' expected but `I' found

  directories = [C:\Users\arg\Documents\RCT3,C:\Users\arg\Documents\StarCraft II\Accounts\662168\2-S2-1-821040\Replays\Multiplayer]

YAML format

Please add support for YAML as configuration Format.

Empty sections in YAML config cause NullPointerExceptions

Valid YAML file:

mixer:

hardware:
    device: "/dev/ttyUSB0"

Code to load it:

Configuration.load("config.yaml", YAMLFormat)

Traceback:

Exception in thread "main" java.lang.NullPointerException
    at org.streum.configrity.yaml.YAMLFormat$.org$streum$configrity$yaml$YAMLFormat$$readValue(YAMLFormat.scala:70)
    at org.streum.configrity.yaml.YAMLFormat$$anonfun$readMap$1.apply(YAMLFormat.scala:62)
    at org.streum.configrity.yaml.YAMLFormat$$anonfun$readMap$1.apply(YAMLFormat.scala:61)
    at scala.collection.TraversableOnce$$anonfun$foldLeft$1.apply(TraversableOnce.scala:144)
    at scala.collection.TraversableOnce$$anonfun$foldLeft$1.apply(TraversableOnce.scala:144)
    at scala.collection.immutable.Map$Map3.foreach(Map.scala:154)
    at scala.collection.TraversableOnce$class.foldLeft(TraversableOnce.scala:144)
    at scala.collection.AbstractTraversable.foldLeft(Traversable.scala:105)
    at org.streum.configrity.yaml.YAMLFormat$.readMap(YAMLFormat.scala:61)
    at org.streum.configrity.yaml.YAMLFormat$.yaml2map(YAMLFormat.scala:52)
    at org.streum.configrity.yaml.YAMLFormat$.fromText(YAMLFormat.scala:34)
    at org.streum.configrity.Configuration$.load(Configuration.scala:231)
    at org.streum.configrity.Configuration$.load(Configuration.scala:246)
    at my.code.Blub$.load(Config.scala:132)

Bug when saving/loading an empty String

Hey there, it looks like I found another bug. It seems like configrity saves empty string like so:

 some.key = 

but isn't able to parse such format. It throws following error:

! org.streum.configrity.io.StandardFormat$ParserException: [7.12] failure: `}' expected but `=' found
! 
!   password = 
! 
!            ^
!   at org.streum.configrity.io.StandardFormat$Parser$class.parse(StandardFormat.scala:78)

Adding manually " " into config file resolves the issue.

Allow Configuration to carry its context name

In a system where a big Configuratin is read from various sources and then different sections are detached and provided to components for internal configuration.

This components need to report configuration errors but, as is, can't report correctly the full path since the detached config doesn't carry the "path" from where it was detached.

So it would be nice if when you detach a configuration it would keep a string with de parameter passed to detach itself and expose it through a simple read-only property.

val configuration = Configuration(....)
val detached = configuration.detach("some.config.section")
// then:
assert detached.contextName == "some.config.section"

I gave not much thought to the contextName name.

If this makes general sense, I can offer a patch.

Support strings formed by single quotes

I suddenly found myself needing strings with double quotes, and there seems to be no way of adding them. A simple solution would be to allow strings formed by single quotes, though that would still leave out things that need both single and double quotes.

Release for Scala 2.10.0

There doesn't seem to be a Configrity release for Scala 2.10.0.

Scala 2.10 has not been announced publicly, but it has already been released to
Typesafe repositories so that library authors can make a version of their library
available for 2.10 prior to its public announcement. This makes the release process
go smoother (and people will be happier to upgrade).

It woud be great to have a release of Configrity for Scala 2.10 available as well.

Add substitute environment variables feature.

Hi there,

I wonder if it is possible to add usage of environmental variables in a config file? The thing is I rely on the env variable that has a changeable value.

I'd like to be able to use the style similar to the following one:

my.env=${MY_ENV}

As I understand TypeSafe config has this feature.

Best regards,

Dmytro Zhydchenko.

Please allow native Scala List for values

To configure a value in the code which represents a List we have to write something like this:

val config = Configuration(
...
"some.key.1" -> "[10]"
"some.key.2" -> "["some string"]"
...
)

which looks ugly. What I would like to do is this:

val config = Configuration(
...
"some.key.1" -> List(10)
"some.key.2" -> "some string" :: Nil
...
)

Thanks!

A string value surrounded by double quotes, are inconsistent.

Let me demonstrate.

import org.streum.configrity._
val config = Configuration()
val config2 = config.set("foo",""""bar bar"""")
config2.save("foo.conf")
val config3 = Configuration.load("foo.conf")

val res1 = config2[String]("foo")
val res2 = config3[String]("foo")

Results in res1 equaling "bar bar". However res2 equals bar bar, that is a string that doesn't contain double quotes. What is happening is that while loading Configrity strips off the double quotes.

I think that to be consistent Configrity should keep the double quotes.

Support for Domains.

Configrity could support Domain's which can be picked up from the environment.

This could be used to pick up different config in different environments like Testing, Production, Development.

Configuration setting source precise reporting

When building an application with complex configuration read from many sources it is desirable being able to report precisely on the source location of any given setting when appropriate.

For example when reporting configuration errors it is highly desirable being able to report precisely the source of the conflicting setting to facilitate fixing the situation.

Another example is when reporting some collection of configuration settings for user checking.

I believe for input formats, the "precise source" of the setting would be a pair of location of resource and line number from where the setting effective value has been read.

#-comments not recognized

During the test of an application, we had some comments in the configuration loaded via loadresource, like

# key =

The configuration is always complaining about the wrong assigment:

org.streum.configrity.io.StandardFormat$ParserException: [7.3] failure: `=' expected but `k' found

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.