/
project.go
59 lines (44 loc) · 981 Bytes
/
project.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
package project
import (
"context"
aw "github.com/deanishe/awgo"
"github.com/hirakiuc/alfred-jira-workflow/decorator"
"github.com/hirakiuc/alfred-jira-workflow/resource"
"github.com/hirakiuc/alfred-jira-workflow/subcommand"
)
type Command struct {
subcommand.BaseCommand
}
func NewCommand(args []string) Command {
return Command{
BaseCommand: subcommand.BaseCommand{
Args: args,
},
}
}
func (cmd Command) Run(ctx context.Context, wf *aw.Workflow) {
r := resource.NewProjectResource(wf)
list, err := r.List(ctx)
if err != nil {
wf.FatalError(err)
return
}
d, err := decorator.NewProjectDecorator(wf)
if err != nil {
wf.FatalError(err)
return
}
for _, prj := range list {
v := prj
d.SetTarget(&v)
wf.NewItem(d.GetTitle()).
Subtitle(d.GetSubtitle()).
Arg(prj.Self).
Valid(true)
}
if cmd.HasQuery() {
wf.Filter(cmd.Query())
}
// Show a warning in Alfred if there are no items
wf.WarnEmpty("No projects found.", "")
}