8000 Config report doesn't connect name-adjusted keys together · Issue #153 · japgolly/clear-config · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
8000 Skip to content
Config report doesn't connect name-adjusted keys together #153
Open
@Daenyth

Description

@Daenyth

For example:

  val port = ConfigDef.getOrUse[Port]("server.port", port"8085")
  def configSources[F[_]: Applicative]: ConfigSources[F] = {
    // Allow property names like `foo.bar` to map to environment variables like `FOO_BAR`
    // Taken from https://github.com/japgolly/clear-config/issues/132
    def propertyToEnv(k: ConfigKey): List[ConfigKey] =
      k :: k.map(_.toUpperCase.replace('.', '_')) :: Nil

    ConfigSource.environment[F].mapKeyQueries(propertyToEnv) >
      ConfigSource.propFile[F]("deploy.properties", optional = true)
      ConfigSource.system[F]
  }
  
  def readConfig[F[_]: MonadThrow](log: Logger[F]): F[MainConfig] =
    config.withReport
      .run(configSources[F])
      .flatMap(_.toEither.leftMap(e => new Exception(e) with NoStackTrace {}).liftTo[F])
      .flatMap { case (cfg, report) =>
        // Don't bother reporting unused environment variables, or "system" settings
        val reportMessage = report
          .mapUnused(_.withoutSources(ConfigSourceName.environment, ConfigSourceName.system))
          .full

        log
          .info(reportMessage)
          .as(cfg)
      }

Results in a config report like this:

Used keys (5):
+-----------------+------+-----------------------------------------------------------------+---------+
| Key             | Env  | /Users/gavin/blahblah/blahblahblahblahblah/local-dev.properties | Default |
+-----------------+------+-----------------------------------------------------------------+---------+
| SERVER_PORT     | 8089 |                                                                 |         |
| server.port     |      |                                                                 | 8085    |
+-----------------+------+-----------------------------------------------------------------+---------+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0