organising library files

This commit is contained in:
2024-11-09 20:24:42 +00:00
parent 4a103679ad
commit 4a384f2c5c
6 changed files with 38 additions and 41 deletions

0
haskell/lib/API.hs Normal file
View File

0
haskell/lib/CLI.hs Normal file
View File

View File

0
haskell/lib/JSON.hs Normal file
View File

View File

@@ -1,14 +1,10 @@
{-# LANGUAGE OverloadedStrings #-}
module P2Prc
( runP2Prc
)
module P2Prc ( runP2Prc )
where
import System.Exit
( ExitCode(ExitFailure)
)
import System.Exit ( ExitCode(ExitFailure) )
import System.Process
( readProcessWithExitCode
@@ -25,7 +21,7 @@ import System.Directory
, removeFile
)
import Control.Concurrent (threadDelay)
import Control.Concurrent ( threadDelay )
import Control.Monad
( when
@@ -64,6 +60,7 @@ import Data.Aeson
-- Module: API
runP2Prc :: IO ()
runP2Prc = do
@@ -87,7 +84,6 @@ runP2Prc = do
case eitherP2prcAPI of
(Right p2prcAPI) -> do
let
( MkP2prAPI
{ startServer = startServer
@@ -111,6 +107,8 @@ runP2Prc = do
case eitherStartProcessHandle of
(Right startProcessHandle) -> do
let sleepNSecs i = threadDelay (i * 1000000)
sleepNSecs 5
outputStr <- execListServers
@@ -222,6 +220,9 @@ getP2prcAPI = do
(Left err) -> Left err
-- Module: JSON
newtype MapPortResponse
= MkMapPortResponse
{ ipAddress :: String
@@ -393,6 +394,26 @@ instance FromJSON ServerInfo where
getIPAddress ip4 _ = MkIPv4 ip4
-- Module Error
data Error
= MkUnknownError String
| MkErrorSpawningProcess String
| MkSystemError Int String String
deriving Show
type IOEitherError a = IO (Either Error a)
assignError :: String -> Error
assignError = MkUnknownError
--
-- TODO: add megaparsec to parse Error Messages
--
-- TODO: add error when internet connection is off
-- Module: CLI
data StdInput
= MkEmptyStdInput
| MkStdInputVal String
@@ -403,7 +424,13 @@ instance Show StdInput where
show (MkStdInputVal v) = v
type IOEitherError a = IO (Either Error a)
data CLIOpt
= MkEmptyOpts
| MkOptAtomic String
| MkOptTuple (String, String)
type CLIOptsInput = [String]
type CLICmd = String
eitherExecProcessParser ::
@@ -424,16 +451,6 @@ eitherErrDecode ::
eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack
data CLIOpt
= MkEmptyOpts
| MkOptAtomic String
| MkOptTuple (String, String)
type CLIOptsInput = [String]
type CLICmd = String
eitherExecProcess :: CLICmd -> [CLIOpt] -> StdInput -> IOEitherError String
eitherExecProcess cmd opts input =
do
@@ -484,21 +501,6 @@ eitherErrorDecode esa =
(Right v) -> Right v
data Error
= MkUnknownError String
| MkErrorSpawningProcess String
| MkSystemError Int String String
deriving Show
assignError :: String -> Error
assignError = MkUnknownError
--
-- TODO: add megaparsec to parse Error Messages
--
-- TODO: add error when internet connection is off
getP2PrcCmd :: IOEitherError String
getP2PrcCmd = do
@@ -521,6 +523,8 @@ getP2PrcCmd = do
err -> pure err
-- Module: Environment
cleanEnvironment :: IO ()
cleanEnvironment = do
@@ -561,6 +565,3 @@ cleanEnvironment = do
doesFileExist
removeFile
sleepNSecs :: Int -> IO ()
sleepNSecs i = threadDelay (i * 1000000)

View File

@@ -66,9 +66,7 @@ executable p2prc
-- Other library packages from which modules are imported.
build-depends: base
, text
, p2prc
, process
-- Base language which the package is written in.
default-language: GHC2021
@@ -88,6 +86,4 @@ library
exposed-modules: P2Prc
other-extensions: OverloadedStrings
default-language: GHC2021