aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/cli.lux
blob: 2185f40f3e87e999176889d25bbf9c88895a0be0 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
 [library
  [lux (.except #Build)
   [abstract
    [equivalence (.only Equivalence)]
    [monad (.only do)]]
   [control
    ["<>" parser]]
   [data
    ["[0]" sum]
    ["[0]" product]
    ["[0]" text]]
   [program
    ["cli" \\parser (.only Parser)]]]]
 [//
  [repository
   [identity (.only Identity)]]
  ["/" profile (.only Name)]])

(type .public Compilation
  (Variant
   {#Build}
   {#Test}))

(def any_equivalence
  (Equivalence Any)
  (implementation
   (def (= reference subject)
     true)))

(def compilation_equivalence
  (Equivalence Compilation)
  (sum.equivalence ..any_equivalence
                   ..any_equivalence))

(def compilation
  (Parser Compilation)
  (<>.or (cli.this "build")
         (cli.this "test")))

(type .public Command
  (Variant
   {#Version}
   {#Clean}
   {#POM}
   {#Dependencies}
   {#Install}
   {#Deploy Text Identity}
   {#Compilation Compilation}
   {#Auto Compilation}))

(def .public equivalence
  (Equivalence Command)
  (all sum.equivalence
       ... #Version
       ..any_equivalence
       ... #Clean
       ..any_equivalence
       ... #POM
       ..any_equivalence
       ... #Dependencies
       ..any_equivalence
       ... #Install
       ..any_equivalence
       ... #Deploy
       (all product.equivalence
            text.equivalence
            text.equivalence
            text.equivalence)
       ... #Compilation
       ..compilation_equivalence
       ... #Auto
       ..compilation_equivalence))

(def command'
  (Parser Command)
  (all <>.or
       (cli.this "version")
       (cli.this "clean")
       (cli.this "pom")
       (cli.this "deps")
       (cli.this "install")
       (<>.after (cli.this "deploy")
                 (<>.and cli.any
                         (<>.and cli.any
                                 cli.any)))
       ..compilation
       (<>.after (cli.this "auto")
                 ..compilation)
       ))

(def .public command
  (Parser [(List Name) Command])
  (<>.rec
   (function (_ command)
     (all <>.either
          (<>.after (cli.this "with")
                    (do <>.monad
                      [head cli.any
                       [tail command] command]
                      (in [{.#Item head tail} command])))
          (of <>.monad each (|>> [(list)])
              ..command')
          ))))