-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Cardano.Wallet.Options (#4112)
- [x] Decouple temp directory creation from the environment variables reading by introducing a function parameter. - [x] Extract functions to read environment variables into a separate package. - [x] Extract functions to read command line options into a separate package. - [x] Extract functions to manage temp directories into a separate package `temporary-extra` - [x] Extract utility functions for tracing/logging into a separate package `iohk-monitoring-extra`
- Loading branch information
Showing
32 changed files
with
3,505 additions
and
2,457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 38 additions & 55 deletions
93
lib/application-extras/cardano-wallet-application-extras.cabal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,48 @@ | ||
cabal-version: 3.0 | ||
name: cardano-wallet-application-extras | ||
version: 0.1.0.0 | ||
synopsis: modules to support applications for the cardano wallet | ||
-- description: | ||
license: Apache-2.0 | ||
license-file: LICENSE | ||
author: HAL, Cardano Foundation | ||
maintainer: hal@cardanofoundation.org | ||
-- copyright: | ||
build-type: Simple | ||
extra-doc-files: CHANGELOG.md | ||
-- extra-source-files: | ||
cabal-version: 3.0 | ||
name: cardano-wallet-application-extras | ||
version: 0.1.0.0 | ||
synopsis: modules to support applications for the cardano wallet | ||
license: Apache-2.0 | ||
license-file: LICENSE | ||
author: HAL, Cardano Foundation | ||
maintainer: hal@cardanofoundation.org | ||
build-type: Simple | ||
extra-doc-files: CHANGELOG.md | ||
|
||
common options | ||
library | ||
default-language: Haskell2010 | ||
default-extensions: | ||
OverloadedStrings | ||
NoImplicitPrelude | ||
DerivingStrategies | ||
OverloadedStrings | ||
|
||
ghc-options: | ||
-O2 -Wall -Wincomplete-record-updates -Wincomplete-uni-patterns | ||
-Wunused-foralls -Wunused-foralls | ||
-fprint-explicit-foralls -fprint-explicit-kinds -Wcompat | ||
-Widentities -Werror=incomplete-patterns -Wredundant-constraints | ||
-Wpartial-fields -Wtabs -fhelpful-errors | ||
-fprint-expanded-synonyms -fwarn-unused-do-bind | ||
-fwarn-incomplete-uni-patterns -freverse-errors | ||
-Wunused-foralls -Wunused-foralls -fprint-explicit-foralls | ||
-fprint-explicit-kinds -Wcompat -Widentities | ||
-Werror=incomplete-patterns -Wredundant-constraints | ||
-Wpartial-fields -Wtabs -fhelpful-errors -fprint-expanded-synonyms | ||
-fwarn-unused-do-bind -fwarn-incomplete-uni-patterns | ||
-freverse-errors | ||
|
||
common dependencies | ||
build-depends: | ||
, aeson | ||
, base ^>=4.14.3.0 | ||
, bytestring | ||
, contra-tracer | ||
, deepseq | ||
, exceptions | ||
, fmt | ||
, iohk-monitoring | ||
, network | ||
, network-uri | ||
, optparse-applicative | ||
, random-shuffle | ||
, safe | ||
, streaming-commons | ||
, text | ||
, text | ||
, text-class | ||
, temporary | ||
, time | ||
, tracer-transformers | ||
, transformers | ||
, unliftio | ||
, unliftio-core | ||
exposed-modules: | ||
Cardano.Wallet.Network.Ports | ||
System.Environment.Extended | ||
|
||
library | ||
import: options, dependencies | ||
exposed-modules: | ||
Cardano.Wallet.Logging | ||
Cardano.Wallet.Options | ||
Cardano.Wallet.Network.Ports | ||
build-depends: base ^>=4.14.3.0 | ||
hs-source-dirs: lib | ||
default-language: Haskell2010 | ||
hs-source-dirs: lib | ||
build-depends: | ||
, base ^>=4.14.3.0 | ||
, contra-tracer ^>=0.1.0.2 | ||
, iohk-monitoring ^>=0.1.11.3 | ||
, iohk-monitoring-extra ^>=0.1 | ||
, network ^>=3.1.4.0 | ||
, network-uri ^>=2.6.4.2 | ||
, optparse-applicative ^>=0.17.1 | ||
, random-shuffle ^>=0.0.4 | ||
, safe ^>=0.3.19 | ||
, streaming-commons ^>=0.2.2.6 | ||
, temporary ^>=1.3 | ||
, text ^>=1.2.4.1 | ||
, text-class ^>=2023.7.18 | ||
, unliftio ^>=0.2.24 | ||
, unliftio-core ^>=0.2.1 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module System.Environment.Extended | ||
( module Reexport | ||
, lookupEnvNonEmpty | ||
, isEnvSet | ||
, envFromText | ||
) where | ||
|
||
import System.Environment as Reexport | ||
|
||
import Prelude | ||
|
||
import Control.Monad | ||
( mfilter ) | ||
import Data.Maybe | ||
( isJust ) | ||
import Data.Text.Class | ||
( FromText (..), TextDecodingError ) | ||
import UnliftIO | ||
( MonadIO (liftIO), MonadUnliftIO ) | ||
|
||
import qualified Data.Text as T | ||
|
||
-- | Looks up an environment variable, treating variables which are defined but | ||
-- empty the same as variables which are undefined. | ||
lookupEnvNonEmpty :: MonadUnliftIO m => String -> m (Maybe String) | ||
lookupEnvNonEmpty = liftIO . (mfilter (not . null) <$>) . lookupEnv | ||
|
||
-- | Returns true iff an environment variable is defined and non-empty. | ||
isEnvSet :: MonadUnliftIO m => String -> m Bool | ||
isEnvSet = fmap isJust . lookupEnvNonEmpty | ||
|
||
-- | Parses an environment variable using text-class. | ||
envFromText | ||
:: (MonadUnliftIO m, FromText a) | ||
=> String | ||
-> m (Maybe (Either TextDecodingError a)) | ||
envFromText = liftIO . fmap (fmap (fromText . T.pack)) . lookupEnv |
Oops, something went wrong.