-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.clj
130 lines (122 loc) · 3.34 KB
/
cli.clj
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
(ns monkey.ci.cli
(:require [clojure.walk :as w]
[monkey.ci
[build :as b]
[commands :as cmd]
[config :as config]]))
(def run-build-cmd
{:command "run"
:description "Runs build locally"
:opts [{:as "Script location"
:option "dir"
:short "d"
:type :string
:default b/default-script-dir}
{:as "Pipeline name"
:option "pipeline"
:short "p"
:type :string}
{:as "Git repository url"
:option "git-url"
:short "u"
:type :string}
{:as "Repository branch"
:option "branch"
:short "b"
:type :string}
{:as "Commit id"
:option "commit-id"
:type :string}
{:as "Repository sid"
:option "sid"
:type :string}]
:runs {:command cmd/run-build
:app-mode :cli}})
(def list-build-cmd
{:command "list"
:description "Lists builds for customer or repo"
:runs {:command cmd/list-builds
:app-mode :cli}})
(def watch-cmd
{:command "watch"
:description "Logs build events for customer or repo"
:runs {:command cmd/watch
:app-mode :cli}})
(def build-cmd
{:command "build"
:description "Build commands"
:opts [{:option "server"
:short "s"
:as "Server URL"
:type :string}
{:as "Customer id"
:option "customer-id"
:short "c"
:type :string}
{:as "Repository id"
:option "repo-id"
:short "r"
:type :string}]
:subcommands [run-build-cmd
list-build-cmd
watch-cmd]})
(def server-cmd
{:command "server"
:description "Start MonkeyCI server"
:opts [{:as "Listening port"
:option "port"
:short "p"
:type :int
:default 3000
:env "PORT"}]
:runs {:command cmd/http-server
:requires [:http]
:app-mode :server}})
(def sidecar-cmd
{:command "sidecar"
:description "Run as sidecar"
:opts [{:as "Events file"
:option "events-file"
:short "e"
:type :string
:default :present}
{:as "Start file"
:option "start-file"
:short "s"
:type :string
:default :present}
{:as "Job config"
:option "job-config"
:short "t"
:type :ednfile}]
:runs {:command cmd/sidecar
:app-mode :script}})
(def base-config
{:name "monkey-ci"
:description "MonkeyCI: Powerful build pipeline runner"
:version (config/version)
:opts [{:as "Working directory"
:option "workdir"
:short "w"
:type :string}
{:as "Development mode"
:option "dev-mode"
:type :with-flag
:default false}
{:as "Configuration file"
:option "config-file"
:short "c"
:type :string
:multiple true}]
:subcommands [build-cmd
server-cmd
sidecar-cmd]})
(defn set-invoker
"Updates the cli config to replace the `runs` config with the given invoker."
[conf inv]
(w/prewalk
(fn [x]
(if (and (map-entry? x) (= :runs (first x)))
[:runs (inv (second x))]
x))
conf))