opt-env-conf 0.5.0.0 → 0.5.0.1
raw patch · 4 files changed
+23/−10 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ OptEnvConf.Error: availableCommandsLines :: [CommandDoc a] -> [[Chunk]]
- OptEnvConf.Error: ParseErrorMissingCommand :: ![String] -> ParseErrorMessage
+ OptEnvConf.Error: ParseErrorMissingCommand :: ![CommandDoc ()] -> ParseErrorMessage
- OptEnvConf.Error: ParseErrorUnrecognisedCommand :: !String -> ![String] -> ParseErrorMessage
+ OptEnvConf.Error: ParseErrorUnrecognisedCommand :: !String -> ![CommandDoc ()] -> ParseErrorMessage
Files
- CHANGELOG.md +6/−0
- opt-env-conf.cabal +1/−1
- src/OptEnvConf/Error.hs +13/−7
- src/OptEnvConf/Run.hs +3/−2
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Changelog +## [0.5.0.1] - 2024-08-04++### Changed++* Errors involving commands now show command descriptions.+ ## [0.5.0.0] - 2024-08-03 ### Changed
opt-env-conf.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: opt-env-conf-version: 0.5.0.0+version: 0.5.0.1 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/Error.hs view
@@ -32,8 +32,8 @@ | ParseErrorMissingSwitch !(Maybe OptDoc) | ParseErrorMissingConfVal !(Maybe ConfDoc) | ParseErrorConfigRead !(Maybe ConfDoc) !String- | ParseErrorMissingCommand ![String]- | ParseErrorUnrecognisedCommand !String ![String]+ | ParseErrorMissingCommand ![CommandDoc ()]+ | ParseErrorUnrecognisedCommand !String ![CommandDoc ()] | ParseErrorAllOrNothing | ParseErrorUnrecognised !(NonEmpty String) deriving (Show)@@ -115,14 +115,13 @@ : maybe [] renderConfDoc md ++ [[chunk $ T.pack $ show s]] ParseErrorMissingCommand cs ->- [ ["Missing command, available commands:"],- unwordsChunks $ map (pure . fore yellow . chunk . T.pack) cs- ]+ ["Missing command, available commands:"]+ : availableCommandsLines cs ParseErrorUnrecognisedCommand c cs -> [ [fore red "Unrecognised command: ", fore yellow $ chunk (T.pack c)],- [fore blue "available commands:"],- unwordsChunks $ map (pure . fore yellow . chunk . T.pack) cs+ [fore blue "available commands:"] ]+ ++ availableCommandsLines cs ParseErrorAllOrNothing -> [ ["You are seeing this error because at least one, but not all, of the settings in an allOrNothing (or subSettings) parser have been defined."] ]@@ -130,3 +129,10 @@ ["Unrecognised args: " : unwordsChunks (map (pure . chunk . T.pack) (NE.toList leftovers))], maybe [] (pure . ("see " :) . pure . srcLocChunk) parseErrorSrcLoc ]++availableCommandsLines :: [CommandDoc a] -> [[Chunk]]+availableCommandsLines = map $ \CommandDoc {..} ->+ [ commandChunk commandDocArgument,+ ": ",+ helpChunk commandDocHelp+ ]
src/OptEnvConf/Run.hs view
@@ -453,15 +453,16 @@ debug [syntaxChunk "Commands", ": ", mSrcLocChunk mLoc] ppIndent $ do mS <- ppArg+ let docsForErrors = map (void . commandParserDocs) cs case mS of Nothing -> do debug ["No argument found for choosing a command."]- ppError mLoc $ ParseErrorMissingCommand $ map commandArg cs+ ppError mLoc $ ParseErrorMissingCommand docsForErrors Just s -> do case find ((== s) . commandArg) cs of Nothing -> do debug ["Argument found, but no matching command: ", chunk $ T.pack $ show s]- ppError mLoc $ ParseErrorUnrecognisedCommand s (map commandArg cs)+ ppError mLoc $ ParseErrorUnrecognisedCommand s docsForErrors Just c -> do debug ["Set command to ", commandChunk (commandArg c)] go $ commandParser c