effectful-cli 0.2.10.0 → 0.2.10.1
raw patch · 4 files changed
+27/−7 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +6/−0
- effectful-cli.cabal +1/−1
- src/Effectful/CLI/Config.hs +12/−6
- test/Spec.hs +8/−0
CHANGELOG.md view
@@ -1,3 +1,9 @@+## [2.10.1](https://github.com/haskell-github-trust/effectful-cli/compare/2.10.0...2.10.1) (2026-11-24)++### Bug Fixes++* **set:** allow writing keys in unset sections with default values ([b238669](https://github.com/haskell-github-trust/effectful-cli/commit/b238669de85c7a0408e089ec78be89ceaa78bd9e))+ ## [2.10.0](https://github.com/haskell-github-trust/effectful-cli/compare/2.9.3...2.10.0) (2026-11-17) ### Features
effectful-cli.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: effectful-cli-version: 0.2.10.0+version: 0.2.10.1 synopsis: CLI helpers for the effectful ecosystem description: Please see the README at https://github.com/haskell-github-trust/effectful-cli category: CLI
src/Effectful/CLI/Config.hs view
@@ -14,6 +14,7 @@ import Control.Monad ((<=<)) import Data.Error.CLI (CLIError (..))+import Data.List (isInfixOf) import Data.Map.Strict qualified as Map import Data.Maybe (fromMaybe) import Data.Text (Text)@@ -82,7 +83,8 @@ render v = T.show (prettyValue v) -- | Set a dotted key to 'parseValue' of the raw input, creating intermediate--- tables; the file is only written if the result still decodes as @a@.+-- tables; the file is only written if the result still decodes as @a@,+-- ignoring missing required keys. -- Re-renders the whole file, dropping comments and formatting. -- -- When decoding fails and @key@ is a section of one of the known keys, the@@ -106,14 +108,18 @@ either (throwError . InputError) pure . setKey (T.splitOn "." key) (parseValue raw) =<< readTable path let rendered = T.show (prettyToml table)- case Toml.decode @a rendered of- Failure es ->- throwError- (InputError ("invalid config: " <> T.stripEnd (T.pack (unlines es)) <> sectionHint))- Success _ _ -> liftIO $ do+ case decodeErrors rendered of+ [] -> liftIO $ do createDirectoryIfMissing True (takeDirectory path) T.writeFile path rendered+ es ->+ throwError+ (InputError ("invalid config: " <> T.stripEnd (T.pack (unlines es)) <> sectionHint)) where+ -- missing required keys are tolerated so sections can be filled one key at a time+ decodeErrors r = case Toml.decode @a r of+ Failure es -> filter (not . isInfixOf "missing key: ") es+ Success _ _ -> [] sectionHint = case filter (T.isPrefixOf (key <> ".")) known of [] -> "" ks -> "; " <> key <> " is a section, set one of: " <> T.intercalate ", " ks
test/Spec.hs view
@@ -171,6 +171,14 @@ Left (InputError m) -> "sec is a section, set one of: sec.x, sec.y" `isInfixOf` show m _ -> False + it "sets a key in a section missing required keys" $ do+ path <- (</> "effectful-cli-config-partial-test.toml") <$> getTemporaryDirectory+ r <- runEff . runErrorNoCallStack @CLIError $ do+ setConfigKey @Section [] path "sec.y" "1"+ getConfigKey path "sec.y"+ removeFile path+ r `shouldBe` Right "1"+ it "shows defaults for a missing file and file values over them" $ do dir <- getTemporaryDirectory let missing = dir </> "effectful-cli-config-missing.toml"