8000 Reduce common boilerplate · Issue #132 · japgolly/clear-config · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content {"props":{"docsUrl":"https://docs.github.com/get-started/accessibility/keyboard-shortcuts"}}
Reduce common boilerplate #132
Open
Open
@japgolly

Description

@japgolly

I'm always doing the same thing. Make this easier out-of-the-box:

  def sources: ConfigSources[IO] =
    // Highest pri
    ConfigSource.environment[IO].expandInlineProperties("APP_PROPS").mapKeyQueries(acceptExternalKeyFormat) >
      ConfigSource.propFileOnClasspath[IO]("app.properties", optional = true) >
      ConfigSource.system[IO]
  // Lowest pri

  private def acceptExternalKeyFormat(k: ConfigKey): List[ConfigKey] =
    k :: k.map(_.toUpperCase.replace('.', '_')) :: Nil

  def load: IO[Option[AppConfig]] =
    config
      .withReport
      .run(sources)
      .map { result =>
        result.toEither match {
          case Right((config, report)) =>
            if (config.showUnusedConfig)
              logger.info("Config report\n" + report.full)
            else
              logger.info("Config report\n" + report.sources + "\n\n" + report.used)
            Some(config)
          case Left(err) =>
            logger.error("Invalid config:\n" + err)
            None
        }
      }

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