forked from ForceCLI/force
/
record.go
104 lines (87 loc) · 2.06 KB
/
record.go
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
package main
import (
"fmt"
)
var cmdRecord = &Command{
Run: runRecord,
Usage: "record <command> [<args>]",
Short: "Create, modify, or view records",
Long: `
Create, modify, or view records
Usage:
force record get <object> <id>
force record create <object> [<fields>]
force record update <object> <id> [<fields>]
force record delete <object> <id>
Examples:
force record get User 00Ei0000000000
force record create User Name:"David Dollar" Phone:0000000000
force record update User 00Ei0000000000 State:GA
force record delete User 00Ei0000000000
`,
}
func runRecord(cmd *Command, args []string) {
if len(args) == 0 {
cmd.printUsage()
} else {
switch args[0] {
case "get":
runRecordGet(args[1:])
case "create", "add":
runRecordCreate(args[1:])
case "update":
runRecordUpdate(args[1:])
case "delete", "remove":
runRecordDelete(args[1:])
default:
ErrorAndExit("no such command: %s", args[0])
}
}
}
func runRecordGet(args []string) {
if len(args) != 2 {
ErrorAndExit("must specify object and id")
}
force, _ := ActiveForce()
object, err := force.GetRecord(args[0], args[1])
if err != nil {
ErrorAndExit(err.Error())
} else {
DisplayForceRecord(object)
}
}
func runRecordCreate(args []string) {
if len(args) < 1 {
ErrorAndExit("must specify object")
}
force, _ := ActiveForce()
attrs := ParseArgumentAttrs(args[1:])
id, err := force.CreateRecord(args[0], attrs)
if err != nil {
ErrorAndExit(err.Error())
}
fmt.Printf("Record created: %s\n", id)
}
func runRecordUpdate(args []string) {
if len(args) < 2 {
ErrorAndExit("must specify object and id")
}
force, _ := ActiveForce()
attrs := ParseArgumentAttrs(args[2:])
err := force.UpdateRecord(args[0], args[1], attrs)
if err != nil {
ErrorAndExit(err.Error())
}
fmt.Println("Record updated")
}
func runRecordDelete(args []string) {
if len(args) != 2 {
ErrorAndExit("must specify object and id")
}
force, _ := ActiveForce()
err := force.DeleteRecord(args[0], args[1])
if err != nil {
ErrorAndExit(err.Error())
}
fmt.Println("Record deleted")
}