blob: d53bccd3d4e467d07c5bc27c2d0e92f2d3288b48 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE NoImplicitPrelude #-}
-- : out agent
-- : dep temporary
module Omni.Agent where
import Alpha
import qualified Data.Text as Text
import qualified Omni.Agent.Core as Core
import qualified Omni.Agent.Worker as Worker
import qualified Omni.Cli as Cli
import qualified Omni.Test as Test
import qualified System.Console.Docopt as Docopt
main :: IO ()
main = Cli.main plan
plan :: Cli.Plan ()
plan =
Cli.Plan
{ Cli.help = help,
Cli.move = move,
Cli.test = test,
Cli.tidy = \_ -> pure ()
}
help :: Cli.Docopt
help =
[Cli.docopt|
agent
Usage:
agent start <name> [--path=<path>]
agent test
agent --help
Options:
--path=<path> Path to the worker directory [default: .]
--help Show this help
|]
move :: Cli.Arguments -> IO ()
move args
| args `Cli.has` Cli.command "start" = do
name <-
Cli.getArg args (Cli.argument "name") |> \case
Just n -> pure (Text.pack n)
Nothing -> panic "Name required"
let path = Cli.getArgWithDefault args "." (Cli.longOption "path")
let worker =
Core.Worker
{ Core.workerName = name,
Core.workerPid = Nothing,
Core.workerStatus = Core.Idle,
Core.workerPath = path
}
Worker.start worker
| otherwise = putStrLn (Cli.usage help)
test :: Test.Tree
test = Test.group "Omni.Agent" [unitTests]
unitTests :: Test.Tree
unitTests =
Test.group
"Unit tests"
[ Test.unit "can parse start command" <| do
let result = Docopt.parseArgs help ["start", "worker-1"]
case result of
Left err -> Test.assertFailure <| "Failed to parse 'start': " <> show err
Right args -> args `Cli.has` Cli.command "start" Test.@?= True
]
|