Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support array as system properties #86

Closed
aloiscochard opened this issue Sep 17, 2013 · 1 comment
Closed

Support array as system properties #86

aloiscochard opened this issue Sep 17, 2013 · 1 comment

Comments

@aloiscochard
Copy link

We had to pimp Config and add this:

  def getStringSeq(path: String): Seq[String] = {
    underlying.getValue(path).valueType match {
      case LIST => underlying.getStringList(path).asScala
      case STRING => 
        val value = underlying.getString(path)
        arrayCircumfix.lift(value).map(_.split(",").map(_.trim).toSeq).getOrElse { 
          sys.error(s"Unable to read value $path, invalid array: $value")
        }
      case tpe => sys.error(s"Unable to read value $path, type $tpe not supported")
    }
  }

To being able to pass "-Dkey=[a,b,c]" as system properties and got it correctly in the app.

There is a weird dichotomy between how value are read form file vs system properties... I tried to fix in source but I was very confuse so I did this hack.

That would be great if you can fix this as it's very useful feature.

@havocp
Copy link
Collaborator

havocp commented Sep 17, 2013

See #69 for past discussion/fix. We did the somewhat clunky -Dkey.0=a -Dkey.1=b to avoid any escaping/quoting, for reasons discussed on that issue.

In general and when possible I think it's better to create a file like "myserver.conf" and do -Dconfig.file=myserver.conf instead of using command line for complex properties.

The dichotomy is not really weird I don't think, though it may not be obvious... properties have Java properties syntax and .conf files have HOCON (or JSON, it's a superset) syntax. Properties syntax does not have lists, only strings. We support some JSON stuff (boolean, number) from properties by offering an automatic conversion from string to boolean/number, but there are a lot more hard questions that arise if you try to implicitly convert from types with syntax (such as object and list). Those conversions would likely create bugs, surprising behavior, and confusing error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants