packages feed

opt-env-conf 0.15.0.3 → 0.16.0.0

raw patch · 4 files changed

+64/−30 lines, 4 filesdep ~autodocodec-nixPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: autodocodec-nix

API changes (from Hackage documentation)

- OptEnvConf.Nix: parserNixOptionExpr :: Parser a -> Expr
- OptEnvConf.Nix: renderParserNixOptions :: Parser a -> Text
- OptEnvConf.Nix: renderParserNixOptionsWithGeneratedComment :: String -> Parser a -> Text
- OptEnvConf.Nix: renderSettingsNixOptions :: HasParser a => Text
- OptEnvConf.Nix: renderSettingsNixOptionsWithGeneratedComment :: HasParser a => String -> Text
+ OptEnvConf.Nix: renderParserNixOptionType :: Parser a -> Text
+ OptEnvConf.Nix: renderParserNixOptionTypeWithGeneratedComment :: String -> Parser a -> Text
+ OptEnvConf.Nix: renderSettingsNixOptionType :: HasParser a => Text
+ OptEnvConf.Nix: renderSettingsNixOptionTypeWithGeneratedComment :: HasParser a => String -> Text

Files

CHANGELOG.md view
@@ -1,5 +1,30 @@ # Changelog +## [0.16.0.0] - 2026-11-14++### Added++* `renderSettingsNixOptionType`, `renderParserNixOptionType` and their+  `WithGeneratedComment` variants.++### Changed++* A setting that is not set is left out of the settings' value instead of+  being `null`.+* `--render-nix-options` is now `--render-nix-option-type`.+* The generated type needs nixpkgs 25.11 or newer.+* The Nix option of a setting with a default documents that default.++### Removed++* `renderSettingsNixOptions`, `renderParserNixOptions`, their+  `WithGeneratedComment` variants and `parserNixOptionExpr`.++### Fixed++* The generated file comment no longer comments out the first line of the+  rendered Nix.+ ## [0.15.0.3] - 2026-08-11  ### Changed
opt-env-conf.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           opt-env-conf-version:        0.15.0.3+version:        0.16.0.0 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@@ -53,7 +53,7 @@   build-depends:       aeson     , autodocodec >=0.3.0.0-    , autodocodec-nix+    , autodocodec-nix >=0.2.0.0     , autodocodec-schema     , autodocodec-yaml     , base <5
src/OptEnvConf/Main.hs view
@@ -141,9 +141,9 @@                     tc <- getTerminalCapabilitiesFromHandle stdout                     hPutChunksLocaleWith tc stdout $ renderReferenceDocumentation progname docs                     exitSuccess-                  RenderNixosOptions -> do+                  RenderNixOptionType -> do                     progname <- getProgName-                    putStrLn $ T.unpack $ renderParserNixOptionsWithGeneratedComment progname p'+                    putStrLn $ T.unpack $ renderParserNixOptionTypeWithGeneratedComment progname p'                     exitSuccess                   BashCompletionScript progPath -> do                     progname <- getProgName@@ -210,7 +210,7 @@   = ShowVersion   | RenderMan   | RenderDocumentation-  | RenderNixosOptions+  | RenderNixOptionType   | BashCompletionScript (Path Abs File)   | ZshCompletionScript (Path Abs File)   | FishCompletionScript (Path Abs File)@@ -244,10 +244,10 @@           help "Render reference documentation"         ],       setting-        [ switch RenderNixosOptions,-          long "render-nix-options",+        [ switch RenderNixOptionType,+          long "render-nix-option-type",           hidden,-          help "Render Nix options"+          help "Render the type of a NixOS module's settings"         ],       BashCompletionScript         <$> setting
src/OptEnvConf/Nix.hs view
@@ -10,6 +10,8 @@  import Autodocodec import Autodocodec.Nix+import qualified Data.Aeson as JSON+import qualified Data.Aeson.Types as JSON import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.List.NonEmpty as NE import Data.Map (Map)@@ -19,34 +21,31 @@ import OptEnvConf.Parser import OptEnvConf.Setting -renderSettingsNixOptionsWithGeneratedComment :: forall a. (HasParser a) => String -> Text-renderSettingsNixOptionsWithGeneratedComment progname =-  withGeneratedComment progname (renderSettingsNixOptions @a)+renderSettingsNixOptionTypeWithGeneratedComment :: forall a. (HasParser a) => String -> Text+renderSettingsNixOptionTypeWithGeneratedComment progname =+  withGeneratedComment progname (renderSettingsNixOptionType @a) -renderParserNixOptionsWithGeneratedComment :: String -> Parser a -> Text-renderParserNixOptionsWithGeneratedComment progname p =-  withGeneratedComment progname (renderParserNixOptions p)+renderParserNixOptionTypeWithGeneratedComment :: String -> Parser a -> Text+renderParserNixOptionTypeWithGeneratedComment progname p =+  withGeneratedComment progname (renderParserNixOptionType p)  withGeneratedComment :: String -> Text -> Text withGeneratedComment progname content =   T.pack $-    unlines $-      map-        ("# " <>)-        [ "DO NOT EDIT THIS FILE DIRECTLY",-          "This file was generated by running",-          unwords [progname, "--render-nix-options"],-          T.unpack content-        ]--renderSettingsNixOptions :: forall a. (HasParser a) => Text-renderSettingsNixOptions = renderParserNixOptions (settingsParser :: Parser a)+    unlines+      [ "# DO NOT EDIT THIS FILE DIRECTLY",+        "# This file was generated by running",+        unwords ["#", progname, "--render-nix-option-type"],+        T.unpack content+      ] -renderParserNixOptions :: Parser a -> Text-renderParserNixOptions = renderExpr . parserNixOptionExpr+renderSettingsNixOptionType :: forall a. (HasParser a) => Text+renderSettingsNixOptionType = renderParserNixOptionType (settingsParser :: Parser a) -parserNixOptionExpr :: Parser a -> Expr-parserNixOptionExpr = withNixArgs . optionsExpr . parserNixOptions+-- | The type of a submodule whose value holds only the settings that were+-- defined.+renderParserNixOptionType :: Parser a -> Text+renderParserNixOptionType = renderOptionType . OptionTypeSubmodule . parserNixOptions  parserNixOptions :: Parser a -> Map Text Option parserNixOptions = go@@ -79,7 +78,17 @@                               (optionalFieldWith' p configValSettingCodec)                               (optionalFieldWith p configValSettingCodec)                               (T.pack <$> settingHelp s)-                       in objectCodecNixOptions oc+                          -- The codec can only decode, so the default is only+                          -- documented when what it shows as is a value that+                          -- the codec accepts, like a number or a string.+                          -- What else it shows as is Haskell, not Nix.+                          documentedDefault :: Maybe JSON.Value+                          documentedDefault = do+                            (_, shown) <- settingDefaultValue s+                            v <- JSON.decodeStrictText (T.pack shown)+                            _ <- JSON.parseMaybe (parseJSONVia configValSettingCodec) v+                            pure v+                       in M.map (\o -> o {optionDocumentedDefault = documentedDefault}) $ objectCodecNixOptions oc                     Just rest ->                       let m = go' rest                        in M.singleton p $ emptyOption {optionType = Just (OptionTypeSubmodule m)}