|
@@ -2,19 +2,14 @@ module Main where
|
|
|
|
|
|
|
|
import Prelude
|
|
import Prelude
|
|
|
|
|
|
|
|
-import Data.CodePoint.Unicode (isLetter)
|
|
|
|
|
|
|
+import Command (class HighLevelCommand, CommandError, CommandWithOpts(..), runCommand, runCommand'')
|
|
|
import Data.Either (Either(..))
|
|
import Data.Either (Either(..))
|
|
|
import Data.Generic.Rep (class Generic)
|
|
import Data.Generic.Rep (class Generic)
|
|
|
-import Data.List (List)
|
|
|
|
|
import Data.Show.Generic (genericShow)
|
|
import Data.Show.Generic (genericShow)
|
|
|
import Data.String (codePointFromChar)
|
|
import Data.String (codePointFromChar)
|
|
|
-import Data.Tuple (Tuple(..))
|
|
|
|
|
-import Debug (trace)
|
|
|
|
|
import Effect (Effect)
|
|
import Effect (Effect)
|
|
|
-import Effect.Aff (Aff, launchAff_, try)
|
|
|
|
|
|
|
+import Effect.Aff (launchAff_, try)
|
|
|
import Effect.Class.Console (log, logShow)
|
|
import Effect.Class.Console (log, logShow)
|
|
|
-import Node.ChildProcess.Types (Exit(..))
|
|
|
|
|
-import Node.Library.Execa (execa)
|
|
|
|
|
import Parsing (Parser, runParser)
|
|
import Parsing (Parser, runParser)
|
|
|
import Parsing.Combinators (between, optional)
|
|
import Parsing.Combinators (between, optional)
|
|
|
import Parsing.Combinators.Array (many)
|
|
import Parsing.Combinators.Array (many)
|
|
@@ -31,54 +26,6 @@ main = do
|
|
|
res <- runCommand'' $ RecSelCommand {filePath: "/tmp/dummy_jobs/jobs.rec", recordType: "job_offer"}
|
|
res <- runCommand'' $ RecSelCommand {filePath: "/tmp/dummy_jobs/jobs.rec", recordType: "job_offer"}
|
|
|
logShow res
|
|
logShow res
|
|
|
|
|
|
|
|
-runCli cmd = launchAff_ do
|
|
|
|
|
- res <- runCommand'' cmd
|
|
|
|
|
- logShow res
|
|
|
|
|
-
|
|
|
|
|
-runCommand ∷ String → Array String → Aff (Either CommandError String)
|
|
|
|
|
-runCommand cmd args = do
|
|
|
|
|
- process <- execa cmd args identity
|
|
|
|
|
- result <- process.getResult
|
|
|
|
|
- let
|
|
|
|
|
- ret = case result.exit of
|
|
|
|
|
- Normally 0 -> Right result.stdout
|
|
|
|
|
- _ -> Left $ Tuple result.exit result.stderr
|
|
|
|
|
-
|
|
|
|
|
- pure ret
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-runCommand' ∷ forall e a. (String -> a) -> (CommandError -> e) -> CommandWithOpts → Aff (Either e a)
|
|
|
|
|
-runCommand' handleRes handleErr (CommandWithOpts cmd args) = do
|
|
|
|
|
- res <- runCommand cmd args
|
|
|
|
|
-
|
|
|
|
|
- let
|
|
|
|
|
- ret = case res of
|
|
|
|
|
- Right s -> Right $ handleRes s
|
|
|
|
|
- Left err -> Left $ handleErr err
|
|
|
|
|
-
|
|
|
|
|
- pure ret
|
|
|
|
|
-
|
|
|
|
|
-runCommand'' ∷ forall cmd res err. HighLevelCommand cmd res err => cmd → Aff (Either err res)
|
|
|
|
|
-runCommand'' hlCommand = do
|
|
|
|
|
- let
|
|
|
|
|
- (CommandWithOpts cmd args) = toCommand hlCommand
|
|
|
|
|
- res <- runCommand cmd args
|
|
|
|
|
-
|
|
|
|
|
- let
|
|
|
|
|
- ret = case res of
|
|
|
|
|
- Right s -> Right $ toResult @cmd s
|
|
|
|
|
- Left err -> Left $ fromError @cmd err
|
|
|
|
|
-
|
|
|
|
|
- pure ret
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-data CommandWithOpts = CommandWithOpts String (Array String)
|
|
|
|
|
-type CommandError = Tuple Exit String
|
|
|
|
|
-
|
|
|
|
|
-class HighLevelCommand cmd res err | cmd -> res, cmd -> err where
|
|
|
|
|
- toCommand :: cmd -> CommandWithOpts
|
|
|
|
|
- toResult :: String -> res
|
|
|
|
|
- fromError :: CommandError -> err
|
|
|
|
|
|
|
|
|
|
data RecSelCommand = RecSelCommand {filePath :: String, recordType :: String}
|
|
data RecSelCommand = RecSelCommand {filePath :: String, recordType :: String}
|
|
|
data RecSelCommandResult = RecSelCommandResult (Array RecFileRecord)
|
|
data RecSelCommandResult = RecSelCommandResult (Array RecFileRecord)
|