-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (75 loc) · 1.48 KB
/
main.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
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"github.com/mickael/zuo/internal/command"
"github.com/mickael/zuo/internal/print"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "zuo",
Usage: "Command-line interface to Zuora",
Commands: []*cli.Command{
{
Name: "query",
Aliases: []string{"q"},
Usage: "Queries a Zuora object by its ID",
Action: func(c *cli.Context) error {
fmt.Printf(
"querying %s with id %s\n",
c.Args().Get(0),
c.Args().Get(1),
)
return nil
},
},
{
Name: "exec",
Usage: "Executes a ZOQL query",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "json",
Usage: "Raw JSON from Zuora",
},
},
Action: func(c *cli.Context) error {
queryString := c.Args().Get(0)
if len(queryString) == 0 {
fmt.Println("query is required")
return nil
}
resp := command.Query(queryString)
if c.Bool("json") {
json, err := json.Marshal(resp)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(json))
} else {
fmt.Printf(
"Found %d record(s)\n",
resp.Size,
)
print.Table(resp.Records)
}
return nil
},
},
{
Name: "login",
Usage: "Generates an access token from Zuora",
Action: func(c *cli.Context) error {
fmt.Println("login...")
return nil
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}