packages feed

etc 0.3.1.0 → 0.3.2.0

raw patch · 9 files changed

+54/−44 lines, 9 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+0.3.2.0+----++* Upgrade to `rio` to version `0.1.1.0`+ 0.3.1.0 ---- 
etc.cabal view
@@ -1,5 +1,5 @@ name: etc-version: 0.3.1.0+version: 0.3.2.0 cabal-version: >=1.10 build-type: Simple license: MIT
src/System/Etc/Internal/Extra/Printer.hs view
@@ -9,11 +9,12 @@   , hPrintPrettyConfig   ) where -import           RIO         hiding ((<>))-import qualified RIO.HashMap as HashMap-import           RIO.List    (intersperse, maximum)-import qualified RIO.Set     as Set-import qualified RIO.Text    as Text+import           RIO              hiding ((<>))+import qualified RIO.HashMap      as HashMap+import           RIO.List         (intersperse)+import           RIO.List.Partial (maximum)+import qualified RIO.Set          as Set+import qualified RIO.Text         as Text  import qualified Data.Aeson as JSON @@ -82,9 +83,13 @@     renderSources :: Text -> [ConfigSource] -> Doc     renderSources keys sources0 =       let+        -- NOTE: I've already checked for the list to not be empty,+        -- so is safe to do this destructuring here         sources@(((selValueDoc, _), selSourceDoc) : others) =           map (renderSource keys) sources0 +        -- NOTE: I've already checked for the list to not be empty,+        -- so is safe to use partial function maximum here         fillingWidth  = sources & map (snd . fst) & maximum & max 10          selectedValue = [greenColor $ fill fillingWidth selValueDoc <+> selSourceDoc]
src/System/Etc/Internal/Resolver/Cli/Common.hs view
@@ -60,8 +60,12 @@  specToCliSwitchFieldMod specSettings =   maybe Opt.idm (Opt.long . Text.unpack) (Spec.optLong specSettings)-    `mappend` maybe Opt.idm (Opt.short . Text.head)  (Spec.optShort specSettings)+    `mappend` maybe Opt.idm Opt.short                shortOption     `mappend` maybe Opt.idm (Opt.help . Text.unpack) (Spec.optHelp specSettings)+ where+  shortOption = do+    shortStr <- Spec.optShort specSettings+    fst <$> Text.uncons shortStr  specToCliVarFieldMod specSettings = specToCliSwitchFieldMod specSettings   `mappend` maybe Opt.idm (Opt.metavar . Text.unpack) (Spec.optMetavar specSettings)@@ -87,22 +91,22 @@   in     requiredCombinator $ case specSettings of       Spec.Opt{} -> case Spec.optValueType specSettings of-        Spec.StringOpt -> (boolToValue sensitive . JSON.String . Text.pack)-          <$> Opt.strOption (specToCliVarFieldMod specSettings)+        Spec.StringOpt -> boolToValue sensitive . JSON.String . Text.pack <$> Opt.strOption+          (specToCliVarFieldMod specSettings) -        Spec.NumberOpt ->-          (boolToValue sensitive . JSON.Number . fromInteger)-            <$> Opt.option Opt.auto (specToCliVarFieldMod specSettings)+        Spec.NumberOpt -> boolToValue sensitive . JSON.Number . fromInteger <$> Opt.option+          Opt.auto+          (specToCliVarFieldMod specSettings) -        Spec.SwitchOpt -> (boolToValue sensitive . JSON.Bool)-          <$> Opt.switch (specToCliSwitchFieldMod specSettings)+        Spec.SwitchOpt -> boolToValue sensitive . JSON.Bool <$> Opt.switch+          (specToCliSwitchFieldMod specSettings)        Spec.Arg{} -> case Spec.argValueType specSettings of         Spec.StringArg ->-          (boolToValue sensitive . JSON.String . Text.pack) <$> Opt.strArgument+          boolToValue sensitive . JSON.String . Text.pack <$> Opt.strArgument             (specSettings & Spec.argMetavar & maybe Opt.idm (Opt.metavar . Text.unpack))         Spec.NumberArg ->-          (boolToValue sensitive . JSON.Number . fromInteger) <$> Opt.argument+          boolToValue sensitive . JSON.Number . fromInteger <$> Opt.argument             Opt.auto             (specSettings & Spec.argMetavar & maybe Opt.idm (Opt.metavar . Text.unpack)) 
src/System/Etc/Internal/Resolver/File.hs view
@@ -146,7 +146,7 @@           Just filePath -> do             envFilePath <- lookupEnv (Text.unpack filePath)             let envPath =-                  maybeToList ((EnvVarFileSource filePath . Text.pack) <$> envFilePath)+                  maybeToList (EnvVarFileSource filePath . Text.pack <$> envFilePath)             return $ map FilePathSource paths0 ++ envPath      paths <- getPaths
src/System/Etc/Internal/Types.hs view
@@ -39,7 +39,7 @@       Sensitive a -> Sensitive (f a)  instance Applicative Value where-  pure a = Plain a+  pure = Plain   (<*>) vf va =     case (vf, va) of       (Plain f, Plain a)         -> Plain (f a)
test/System/Etc/Extra/EnvMisspellTest.hs view
@@ -8,7 +8,7 @@ import qualified RIO.Vector as Vector  import Test.Tasty       (TestTree, testGroup)-import Test.Tasty.HUnit (assertBool, assertEqual, testCase)+import Test.Tasty.HUnit (assertEqual, assertFailure, testCase)  import System.Etc @@ -23,11 +23,11 @@        (spec :: ConfigSpec ()) <- parseConfigSpec input -      let result = getEnvMisspellingsPure spec ["GREEING"]--      assertBool "expecting to get a warning for typo" (not $ Vector.null result)+      let result0 = getEnvMisspellingsPure spec ["GREEING"] -      assertEqual "expecting to get typo for key GREETING"-                  (EnvMisspell "GREEING" "GREETING")-                  (Vector.head result)+      case result0 Vector.!? 0 of+        Nothing     -> assertFailure "expecting to get a warning for typo"+        Just result -> assertEqual "expecting to get typo for key GREETING"+                                   (EnvMisspell "GREEING" "GREETING")+                                   result   ]
test/System/Etc/Resolver/Cli/CommandTest.hs view
@@ -106,7 +106,7 @@           , "    \"desc\": \"\""           , "  , \"header\": \"\""           , "  , \"commands\": {"-          , "      \"test\": {\"header\": \"\", \"desc\": \"\"}}}"+          , "      \"test1\": {\"header\": \"\", \"desc\": \"\"}}}"           , ", \"etc/entries\": {"           , "    \"greeting\": {"           , "      \"etc/spec\": {"@@ -116,13 +116,13 @@           , "        , \"long\": \"greeting\""           , "        , \"type\": \"string\""           , "        , \"required\": false"-          , "        , \"commands\": [\"test\"]"+          , "        , \"commands\": [\"test1\"]"           , "}}}}}"           ]     (spec :: ConfigSpec Text) <- parseConfigSpec input-    (cmd, config)             <- resolveCommandCliPure spec "program" ["test"]+    (cmd, config)             <- resolveCommandCliPure spec "program" ["test1"] -    assertEqual "invalid command output" "test" cmd+    assertEqual "invalid command output" "test1" cmd      case getConfigValue ["greeting"] config of       Just aSet ->
test/System/Etc/Resolver/DefaultTest.hs view
@@ -10,36 +10,32 @@ import           Test.Tasty       (TestTree, testGroup) import           Test.Tasty.HUnit (assertBool, assertFailure, testCase) -- import System.Etc +assertDefaultValue :: Config -> [Text] -> Value JSON.Value -> IO ()+assertDefaultValue config keys val = case getAllConfigSources keys config of+  Nothing   -> assertFailure ("expecting to get entries for greeting\n" <> show config)+  Just aSet -> assertBool ("expecting to see entry from env; got " <> show aSet)+                          (Set.member (Default val) aSet)+ tests :: TestTree tests = testGroup   "default"   [ testCase "default is used when defined on spec" $ do     let input = mconcat           [ "{\"etc/entries\": {"-          , " \"greeting\": { \"etc/spec\": { \"default\": \"hello default\" }}}}"+          , " \"greeting\": { \"etc/spec\": { \"default\": \"hello default 1\" }}}}"           ]-    (spec :: ConfigSpec ()) <- parseConfigSpec input +    (spec :: ConfigSpec ()) <- parseConfigSpec input     let config = resolveDefault spec--    case getAllConfigSources ["greeting"] config of-      Nothing   -> assertFailure ("expecting to get entries for greeting\n" <> show config)-      Just aSet -> assertBool ("expecting to see entry from env; got " <> show aSet)-                              (Set.member (Default "hello default") aSet)+    assertDefaultValue config ["greeting"] "hello default 1"   , testCase "default can be raw JSON value on entries spec" $ do-    let input = mconcat ["{\"etc/entries\": {", " \"greeting\": \"hello default\"}}"]+    let input = mconcat ["{\"etc/entries\": {", " \"greeting\": \"hello default 2\"}}"]     (spec :: ConfigSpec ()) <- parseConfigSpec input      let config = resolveDefault spec--    case getAllConfigSources ["greeting"] config of-      Nothing   -> assertFailure ("expecting to get entries for greeting\n" <> show config)-      Just aSet -> assertBool ("expecting to see entry from env; got " <> show aSet)-                              (Set.member (Default "hello default") aSet)+    assertDefaultValue config ["greeting"] "hello default 2"   , testCase "default can be a null JSON value" $ do     let input = mconcat ["{\"etc/entries\": {", " \"greeting\": null}}"]     (spec :: ConfigSpec ()) <- parseConfigSpec input