/
fetch_jobs_flow.go
70 lines (58 loc) · 1.42 KB
/
fetch_jobs_flow.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
package command
import (
"bytes"
"fmt"
"github.com/jessevdk/go-flags"
"github.com/k0kubun/pp"
"github.com/mitchellh/cli"
"github.com/prokosna/dementor/lib"
)
type FetchJobsCommand struct {
Ui cli.Ui
}
var fetchJobsOpts struct {
Project string `short:"p" long:"project" description:"Project name" required:"true"`
Flow string `short:"f" long:"flowId" description:"Flow ID" required:"true"`
dementor.CommonConf
}
var fetchJobsParser *flags.Parser
func init() {
fetchJobsParser = flags.NewParser(&fetchJobsOpts, flags.IgnoreUnknown|flags.HelpFlag|flags.PassDoubleDash)
}
func (c *FetchJobsCommand) Run(args []string) int {
_, err := fetchJobsParser.ParseArgs(args)
if err != nil {
c.Ui.Error(err.Error())
c.Ui.Output(c.Help())
return 1
}
id, err := getSessionId(fetchJobsOpts.CommonConf)
if err != nil {
c.Ui.Error(err.Error())
return 1
}
req := &dementor.FetchJobsFlowReq{
Project: fetchJobsOpts.Project,
Flow: fetchJobsOpts.Flow,
CommonConf: fetchJobsOpts.CommonConf,
}
res, err := dementor.FetchJobsFlow(
id,
req,
)
if err != nil {
c.Ui.Error(err.Error())
return 1
}
pretty := pp.Sprint(*res)
c.Ui.Info(fmt.Sprintf("Successfully fetched the jobs: \n%s", pretty))
return 0
}
func (c *FetchJobsCommand) Help() string {
buf := new(bytes.Buffer)
fetchJobsParser.WriteHelp(buf)
return buf.String()
}
func (c *FetchJobsCommand) Synopsis() string {
return "Fetch jobs of the flow."
}