This repository has been archived by the owner on May 13, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
add.pony
52 lines (45 loc) · 1.42 KB
/
add.pony
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
use "json"
use options = "options"
primitive Add
fun apply(args: Array[String] box, log: Log): JsonObject ? =>
let kind = args(0)?
let rest = args.slice(1)
let prim =
match kind
| "github" => AddGitHosted
| "gitlab" => AddGitHosted
| "local-git" => AddLocalGit
| "local" => AddLocal
else
log("Couldn't find type '" + kind + "'.")
log("Available types are github, gitlab, local-git, and local.")
error
end
let info: JsonObject ref = JsonObject
info.data("type") = kind.clone()
prim(rest, info)?
info
primitive AddGitHosted
fun apply(args: Array[String] box, info: JsonObject) ? =>
info.data("repo") = args(0)?
let opts = options.Options(args.slice(1))
opts.add("tag", "t", options.StringArgument)
opts.add("subdir", "d", options.StringArgument)
for opt in opts do
match opt
| (let name: String, let value: String) => info.data(name) = value
end
end
primitive AddLocalGit
fun apply(args: Array[String] box, info: JsonObject) ? =>
info.data("local-path") = args(0)?
let opts = options.Options(args.slice(1))
opts.add("tag", "t", options.StringArgument)
for opt in opts do
match opt
| (let name: String, let value: String) => info.data(name) = value
end
end
primitive AddLocal
fun apply(args: Array[String] box, info: JsonObject) ? =>
info.data("local-path") = args(0)?