From 7690c0179b210d1a9aca2c22f09de2364d60ed52 Mon Sep 17 00:00:00 2001 From: Roman Gonzalez Date: Mon, 17 Apr 2017 01:47:46 +0000 Subject: [PATCH 1/8] Update chmod of .ghci for enabling it on intero --- .ghci | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .ghci diff --git a/.ghci b/.ghci old mode 100644 new mode 100755 From c4e514fb0eb21ac5b690882f5d38ebabb93c6acd Mon Sep 17 00:00:00 2001 From: Roman Gonzalez Date: Mon, 17 Apr 2017 01:49:25 +0000 Subject: [PATCH 2/8] [#3] Add support for `null` default value --- etc/src/System/Etc/Internal/Extra/Printer.hs | 3 +++ etc/test/System/Etc/Resolver/DefaultTest.hs | 24 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/etc/src/System/Etc/Internal/Extra/Printer.hs b/etc/src/System/Etc/Internal/Extra/Printer.hs index 34d45c9..d7b4454 100644 --- a/etc/src/System/Etc/Internal/Extra/Printer.hs +++ b/etc/src/System/Etc/Internal/Extra/Printer.hs @@ -21,6 +21,9 @@ import System.Etc.Internal.Types renderJsonValue :: JSON.Value -> (Doc, Int) renderJsonValue value' = case value' of + JSON.Null -> + (text "null", 4) + JSON.String str -> (text $ Text.unpack str, Text.length str) diff --git a/etc/test/System/Etc/Resolver/DefaultTest.hs b/etc/test/System/Etc/Resolver/DefaultTest.hs index 4a9ac65..355faa3 100644 --- a/etc/test/System/Etc/Resolver/DefaultTest.hs +++ b/etc/test/System/Etc/Resolver/DefaultTest.hs @@ -5,6 +5,7 @@ module System.Etc.Resolver.DefaultTest (tests) where import Protolude +import qualified Data.Aeson as JSON import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit (assertBool, assertFailure, testCase) @@ -61,4 +62,27 @@ tests = assertBool ("expecting to see entry from env; got " <> show set) (Set.member (Default "hello default") set) + , testCase "default can be a null JSON value" $ do + let + input = + mconcat + [ + "{\"etc/entries\": {" + , " \"greeting\": null}}" + ] + (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 set -> + assertBool ("expecting to see entry from env; got " <> show set) + (Set.member (Default JSON.Null) set) + + ] From 6bd63ff0a5066090227b55c557ed8da879963bda Mon Sep 17 00:00:00 2001 From: Roman Gonzalez Date: Mon, 17 Apr 2017 01:50:26 +0000 Subject: [PATCH 3/8] [#3] Remove ConfigSpec explicit type when cabal cli flag is off --- etc/src/System/Etc/Spec.hs | 16 ++++++++++++++++ etc/test/System/Etc/SpecTest.hs | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/etc/src/System/Etc/Spec.hs b/etc/src/System/Etc/Spec.hs index 9a7d169..8b98209 100644 --- a/etc/src/System/Etc/Spec.hs +++ b/etc/src/System/Etc/Spec.hs @@ -15,7 +15,9 @@ import System.Etc.Internal.Spec.Types as Types import Control.Monad.Catch (MonadCatch (..)) +#ifdef WITH_CLI import qualified Data.Aeson as JSON +#endif import qualified Data.Text as Text import qualified Data.Text.IO as Text (readFile) @@ -30,10 +32,18 @@ Parses a text input into a @ConfigSpec@, input can be JSON or YAML (if cabal flag is set). -} +#ifdef WITH_CLI parseConfigSpec :: (MonadCatch m, JSON.FromJSON cmd) => Text -- ^ Text to be parsed -> m (ConfigSpec cmd) -- ^ returns ConfigSpec +#else +parseConfigSpec + :: (MonadCatch m) + => Text -- ^ Text to be parsed + -> m (ConfigSpec ()) -- ^ returns ConfigSpec +#endif + #ifdef WITH_YAML parseConfigSpec input = catch (JSON.parseConfigSpec input) @@ -49,10 +59,16 @@ Reads contents of a file and parses into a @ConfigSpec@, file contents can be either JSON or YAML (if cabal flag is set). -} +#ifdef WITH_CLI readConfigSpec :: JSON.FromJSON cmd => Text -- ^ Filepath where contents are going to be read from and parsed -> IO (ConfigSpec cmd) -- ^ returns ConfigSpec +#else +readConfigSpec + :: Text -- ^ Filepath where contents are going to be read from and parsed + -> IO (ConfigSpec ()) -- ^ returns ConfigSpec +#endif readConfigSpec filepath = do contents <- Text.readFile $ Text.unpack filepath parseConfigSpec contents diff --git a/etc/test/System/Etc/SpecTest.hs b/etc/test/System/Etc/SpecTest.hs index fa501e6..5bca6e5 100644 --- a/etc/test/System/Etc/SpecTest.hs +++ b/etc/test/System/Etc/SpecTest.hs @@ -170,6 +170,7 @@ general_tests = assertBool "" True ] +#ifdef WITH_CLI cli_tests :: TestTree cli_tests = testGroup "cli" @@ -273,6 +274,7 @@ cli_tests = assertBool "" True ] +#endif envvar_tests :: TestTree envvar_tests = @@ -330,5 +332,7 @@ tests = , yaml_tests #endif , envvar_tests +#ifdef WITH_CLI , cli_tests +#endif ] From 2ace1e5be90397beb20768fa1feb4c4f1322a0d7 Mon Sep 17 00:00:00 2001 From: Roman Gonzalez Date: Mon, 17 Apr 2017 01:50:59 +0000 Subject: [PATCH 4/8] Bump to aeson =4.7 && <5 - , aeson >=0.11 && <1.2 + , aeson >=0.11 && <1.3 , text >=1.2 && <1.3 , protolude >=0.1 && <0.2 , unordered-containers >=0.2 && <0.3 diff --git a/etc-plain-example/etc-plain-example.cabal b/etc-plain-example/etc-plain-example.cabal index 7132bcf..dd50ad8 100644 --- a/etc-plain-example/etc-plain-example.cabal +++ b/etc-plain-example/etc-plain-example.cabal @@ -23,7 +23,7 @@ executable etc-plain-example ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall build-depends: base >=4.7 && <5 - , aeson >=0.11 && <1.2 + , aeson >=0.11 && <1.3 , text >=1.2 && <1.3 , protolude >=0.1 && <0.2 , unordered-containers >=0.2 && <0.3 diff --git a/etc/etc.cabal b/etc/etc.cabal index cf16b69..273e007 100644 --- a/etc/etc.cabal +++ b/etc/etc.cabal @@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: etc -version: 0.0.0.2 +version: 0.0.0.3 synopsis: Declarative configuration spec for Haskell projects description: Please see README.md category: Configuration, System @@ -50,7 +50,7 @@ library ghc-options: -Wall build-depends: base >=4.7 && <5 - , aeson >=0.11 && <1.2 + , aeson >=0.11 && <1.3 , bytestring >=0.10 && <0.11 , containers >=0.5 && <0.6 , text >=1.2 && <1.3 @@ -113,7 +113,7 @@ test-suite etc-testsuite ghc-options: -Wall build-depends: base >=4.7 && <5 - , aeson >=0.11 && <1.2 + , aeson >=0.11 && <1.3 , bytestring >=0.10 && <0.11 , containers >=0.5 && <0.6 , text >=1.2 && <1.3 From 7c9cd2c2d82b6181d6522aec30d82f95c0320000 Mon Sep 17 00:00:00 2001 From: Roman Gonzalez Date: Mon, 17 Apr 2017 01:51:16 +0000 Subject: [PATCH 5/8] Update CHANGELOG --- etc/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/etc/CHANGELOG.md b/etc/CHANGELOG.md index 92b6732..37b60a6 100644 --- a/etc/CHANGELOG.md +++ b/etc/CHANGELOG.md @@ -1,3 +1,10 @@ +0.0.0.3 +---- +* Add support for null values on Default (issue #3) +* If cli cabal flag is false, have `parseConfigSpec` return `ConfigSpec ()` + instead of ambiguous `FromJSON` value (issue #3) +* Bump aeson dependency to `<1.3` + 0.0.0.2 ---- * Rename System.Etc.Internal.Util module to System.Etc.Internal.Extra From 35f0da1bdfa4a9ae78926836919b14c5e629664c Mon Sep 17 00:00:00 2001 From: Roman Gonzalez Date: Mon, 17 Apr 2017 01:52:31 +0000 Subject: [PATCH 6/8] Apeassing Stylish Haskell --- etc/src/System/Etc/Spec.hs | 2 +- etc/test/System/Etc/Resolver/DefaultTest.hs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/etc/src/System/Etc/Spec.hs b/etc/src/System/Etc/Spec.hs index 8b98209..58e6680 100644 --- a/etc/src/System/Etc/Spec.hs +++ b/etc/src/System/Etc/Spec.hs @@ -16,7 +16,7 @@ import System.Etc.Internal.Spec.Types as Types import Control.Monad.Catch (MonadCatch (..)) #ifdef WITH_CLI -import qualified Data.Aeson as JSON +import qualified Data.Aeson as JSON #endif import qualified Data.Text as Text import qualified Data.Text.IO as Text (readFile) diff --git a/etc/test/System/Etc/Resolver/DefaultTest.hs b/etc/test/System/Etc/Resolver/DefaultTest.hs index 355faa3..dccffc5 100644 --- a/etc/test/System/Etc/Resolver/DefaultTest.hs +++ b/etc/test/System/Etc/Resolver/DefaultTest.hs @@ -5,9 +5,9 @@ module System.Etc.Resolver.DefaultTest (tests) where import Protolude -import qualified Data.Aeson as JSON -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.HUnit (assertBool, assertFailure, testCase) +import qualified Data.Aeson as JSON +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.HUnit (assertBool, assertFailure, testCase) import qualified Data.Set as Set From bcf67689dabed7d3960c47fd95792cbda91681f4 Mon Sep 17 00:00:00 2001 From: Roman Gonzalez Date: Mon, 17 Apr 2017 01:59:49 +0000 Subject: [PATCH 7/8] Bump to v0.1.0.0 --- etc/CHANGELOG.md | 2 +- etc/etc.cabal | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/CHANGELOG.md b/etc/CHANGELOG.md index 37b60a6..ee47d10 100644 --- a/etc/CHANGELOG.md +++ b/etc/CHANGELOG.md @@ -1,4 +1,4 @@ -0.0.0.3 +0.1.0.0 ---- * Add support for null values on Default (issue #3) * If cli cabal flag is false, have `parseConfigSpec` return `ConfigSpec ()` diff --git a/etc/etc.cabal b/etc/etc.cabal index 273e007..173c22a 100644 --- a/etc/etc.cabal +++ b/etc/etc.cabal @@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: etc -version: 0.0.0.3 +version: 0.1.0.0 synopsis: Declarative configuration spec for Haskell projects description: Please see README.md category: Configuration, System From 2326fda3c879db4bd3c82a56c8760e53dd465833 Mon Sep 17 00:00:00 2001 From: Roman Gonzalez Date: Mon, 17 Apr 2017 02:48:07 +0000 Subject: [PATCH 8/8] Update README with explicit ConfigSpec signature note --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 1b1c6bf..2f9cf49 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,11 @@ function can accept either a JSON or YAML filepath. You can also use the `System.Etc.parseConfigSpec` if you already gather the contents of a spec file from a different source. +_NOTE_: When using `System.Etc.parseConfigSpec` or `System.Etc.readConfigSpec` +and the [CLI cabal feature flag is true](#cli-support), unless you use the +`System.Etc.resolveCommandCli` function, you will have to explicitly declare the +`ConfigSpec` type parameter. + ### YAML support In order to allow `etc` to read from YAML files, you will need to use the `yaml`