packages feed

opt-env-conf 0.4.0.3 → 0.4.0.4

raw patch · 3 files changed

+27/−4 lines, 3 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ OptEnvConf.Lint: LintErrorUndecodableExample :: !String -> LintErrorMessage

Files

CHANGELOG.md view
@@ -1,5 +1,15 @@ # Changelog +## [0.4.0.4] - 2024-07-28++### Added++* Added a lint for examples that none of the configuration codecs can decode.++### Changed++* Fixed: linter would 'catch' unreadable examples even though a setting would only read a configuration value+ ## [0.4.0.3] - 2024-07-28  ### Changed
opt-env-conf.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           opt-env-conf-version:        0.4.0.3+version:        0.4.0.4 synopsis:       Settings parsing for Haskell: command-line arguments, environment variables, and configuration values. homepage:       https://github.com/NorfairKing/opt-env-conf#readme bug-reports:    https://github.com/NorfairKing/opt-env-conf/issues
src/OptEnvConf/Lint.hs view
@@ -13,8 +13,10 @@   ) where +import Autodocodec import Control.Monad import Control.Monad.Reader+import qualified Data.Aeson.Types as JSON import Data.Either import Data.Foldable import Data.List.NonEmpty (NonEmpty (..))@@ -51,6 +53,7 @@   | LintErrorNoMetavarForEnvVar   | LintErrorNoCommands   | LintErrorUnreadableExample !String+  | LintErrorUndecodableExample !String   | LintErrorConfigWithoutLoad   | LintErrorManyInfinite @@ -192,6 +195,10 @@           [ [functionChunk "example", " was called with an example that none of the ", functionChunk "reader", "s succeed in reading."],             ["Example: ", chunk $ T.pack e]           ]+        LintErrorUndecodableExample e ->+          [ [functionChunk "example", " was called with an example that none of the ", functionChunk "conf", "s succeed in decoding."],+            ["Example: ", chunk $ T.pack e]+          ]         LintErrorConfigWithoutLoad ->           [ [ functionChunk "conf",               " was called with no way to load configuration."@@ -299,9 +306,15 @@         when (isJust settingEnvVars && not settingHidden && isNothing settingMetavar) $           validationTFailure LintErrorNoMetavarForEnvVar         for_ settingExamples $ \e ->-          when (not $ any (\r -> isRight $ OptEnvConf.runReader r e) settingReaders) $-            validationTFailure $-              LintErrorUnreadableExample e+          let canRead r = isRight $ OptEnvConf.runReader r e+           in when ((settingTryArgument || settingTryOption) && not (any canRead settingReaders)) $+                validationTFailure $+                  LintErrorUnreadableExample e+        for_ settingExamples $ \e ->+          let canDecode (ConfigValSetting _ c) = isRight $ JSON.parseEither (parseJSONVia c) (JSON.String (T.pack e))+           in when (isJust settingConfigVals && not (any canDecode (maybe [] NE.toList settingConfigVals))) $+                validationTFailure $+                  LintErrorUndecodableExample e         hasConfig <- ask         when (isJust settingConfigVals && not hasConfig) $           validationTFailure LintErrorConfigWithoutLoad