default config

This commit is contained in:
Dmitry Zuikov 2023-02-15 08:03:29 +03:00
parent eba484575c
commit 9518a4b1c7
4 changed files with 24 additions and 3 deletions

View File

@ -158,3 +158,4 @@ fixme-set "workflow" "wip" "DZyVAuBYzB"
fixme-set "workflow" "test" "DTZ2RqeN7y" fixme-set "workflow" "test" "DTZ2RqeN7y"
fixme-set "workflow" "test" "84iLJsvCtT"

View File

@ -1,6 +1,8 @@
## 2023-02-15 ## 2023-02-15
FIXME: create-default-config
FIXME: wrong-default-config-path FIXME: wrong-default-config-path
TODO: make-key-optional-parameter TODO: make-key-optional-parameter

View File

@ -23,6 +23,7 @@ import System.FilePath
import Data.Set qualified as Set import Data.Set qualified as Set
import Data.Set (Set) import Data.Set (Set)
import Data.Text qualified as Text import Data.Text qualified as Text
import Text.InterpolatedString.Perl6 (qc)
class HasCfgKey a b where class HasCfgKey a b where
-- type family CfgValue a :: Type -- type family CfgValue a :: Type
@ -53,9 +54,21 @@ peerConfigDefault = liftIO $
catchAny :: IO a -> (SomeException -> IO a) -> IO a catchAny :: IO a -> (SomeException -> IO a) -> IO a
catchAny = Control.Exception.catch catchAny = Control.Exception.catch
defConfigData :: String
defConfigData = [qc|
peerConfigInit :: Maybe FilePath -> IO () listen "0.0.0.0:7351"
peerConfigInit mbfp = do rpc "127.0.0.1:13331"
; default storage is $HOME/.local/share/hbs2
; storage "./storage"
; edit path to a keyring file
; key "./key"
|]
peerConfigInit :: MonadIO m => Maybe FilePath -> m ()
peerConfigInit mbfp = liftIO do
debug $ "peerConfigInit" <+> pretty mbfp debug $ "peerConfigInit" <+> pretty mbfp
defDir <- peerConfigDefault <&> takeDirectory defDir <- peerConfigDefault <&> takeDirectory
@ -70,9 +83,13 @@ peerConfigInit mbfp = do
unless here do unless here do
appendFile (dir</>cfgName) ";; hbs2-peer config file" appendFile (dir</>cfgName) ";; hbs2-peer config file"
appendFile (dir</>cfgName) defConfigData
peerConfigRead :: MonadIO m => Maybe FilePath -> m PeerConfig peerConfigRead :: MonadIO m => Maybe FilePath -> m PeerConfig
peerConfigRead mbfp = do peerConfigRead mbfp = do
peerConfigInit mbfp
debug $ "peerConfigRead" <+> pretty mbfp debug $ "peerConfigRead" <+> pretty mbfp
xdg <- peerConfigDefault xdg <- peerConfigDefault

View File

@ -51,6 +51,7 @@ common common-deps
, uniplate , uniplate
, unordered-containers , unordered-containers
, vector , vector
, interpolatedstring-perl6
common shared-properties common shared-properties
ghc-options: ghc-options: