-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply.go
74 lines (61 loc) · 1.26 KB
/
apply.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
package issue
import (
"io/ioutil"
"log"
"github.com/locona/jira/pkg/issue"
"github.com/locona/jira/pkg/prompt"
"github.com/andygrunwald/go-jira"
"github.com/briandowns/spinner"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)
type ApplyOption struct {
FilePath string
}
func NewCommandApply() *cobra.Command {
applyOption := &ApplyOption{}
cmd := &cobra.Command{
Use: "apply",
RunE: func(cmd *cobra.Command, args []string) error {
return Apply(applyOption)
},
}
cmd.Flags().StringVarP(&applyOption.FilePath, "file", "f", "", "Status.")
return cmd
}
type ApplyCommand struct {
Value *issue.ApplyValue
Result []jira.Issue
}
func (cmd *ApplyCommand) Request(s *spinner.Spinner) error {
applied, err := issue.Apply(cmd.Value)
if err != nil {
return err
}
cmd.Result = applied
return nil
}
func (cmd *ApplyCommand) Response() error {
issue.ViewTable(cmd.Result)
return nil
}
func Apply(option *ApplyOption) error {
buf, err := ioutil.ReadFile(option.FilePath)
if err != nil {
return err
}
values := make([]*issue.ApplyValue, 0)
err = yaml.Unmarshal(buf, &values)
if err != nil {
return err
}
for _, v := range values {
err := prompt.Progress(&ApplyCommand{
Value: v,
})
if err != nil {
log.Println(err)
}
}
return nil
}