Coder Social home page Coder Social logo

Concatenated strings as keys about config HOT 5 CLOSED

mslinn avatar mslinn commented on June 25, 2024
Concatenated strings as keys

from config.

Comments (5)

havocp avatar havocp commented on June 25, 2024

I added the following test and it passed. My guess is that you're expecting to use a string with methods that expect a path expression, see the docs for class Config in http://typesafehub.github.com/config/latest/api/

If that isn't it then it would be helpful to modify the test below to break.

    @Test
    def unquotedKeyWithWhitespace() {
        val conf = ConfigFactory.parseString("""repositories {
    AWS S3 : "http://jets3t.s3.amazonaws.com/maven2"
}""")
        assertEquals("http://jets3t.s3.amazonaws.com/maven2", conf.getObject("repositories").get("AWS S3").unwrapped.asInstanceOf[String])
        assertEquals("http://jets3t.s3.amazonaws.com/maven2", conf.getString("repositories.\"AWS S3\""))
    }

from config.

mslinn avatar mslinn commented on June 25, 2024

I've got code like this (you can see the whole file here)

val entireConfig: Config = ConfigFactory.parseURL(new URL(fetchFromUrl))

  /** Work around Config bug */
  def sanitizeKey(key: String) = key.replace("\"", " ").trim

  def makeSettings(lookup: Lookup): SortedMap[String, String] = {
    lookup.config.entrySet foreach { kv =>
      val key = kv.getKey
      val value = kv.getValue.unwrapped.toString
      keyValues.put(sanitizeKey(key), value)
    }
    SortedMap.empty[String, String] ++ (keyValues.toList.sortBy(_._1))
  }

  def apply(key: String) = {
    val sanitizedKey = sanitizeKey(key)
    val value = keyValues.get(sanitizedKey)
    if (value!=None) {
      if (!quiet && !alreadyShown.contains(sanitizedKey)) {
        alreadyShown += sanitizedKey
        println("  %s = %s".format(sanitizedKey, value.get))
      }
      value.get
    } else {
      println("Warning: %s is not defined in the config file at %s".format(sanitizedKey, fetchFromUrl))
      ""
    }
  }

from config.

havocp avatar havocp commented on June 25, 2024

I think your problem is that entrySet on a Config has path expressions as keys. Try config.root.entrySet (but of course you then have a tree of maps, not a single level).

from config.

mslinn avatar mslinn commented on June 25, 2024

I'll stick with my workaround. Might be worthwhile mentioning something about this corner case in the docs.

from config.

havocp avatar havocp commented on June 25, 2024

I think it is mentioned but I'll see if
it can go in more places. To convert between paths and keys, you need to do more than your sanitizeKey does; there are utility methods joinPath and splitPath in ConfigUtil for this. or something like that, I may remember the wrong method names.

from config.

Related Issues (20)

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.