-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow.go
52 lines (43 loc) · 1.07 KB
/
workflow.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
package plexams
import (
"context"
"github.com/gookit/color"
"github.com/obcode/plexams.go/graph/model"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
func initWorkflow() []*model.Step {
var workflow []*model.Step
err := viper.UnmarshalKey("workflow", &workflow)
if err != nil {
log.Fatal().Err(err).Msg("cannot decode workflow with viper")
}
for i, s := range workflow {
s.Number = i + 1
}
return workflow
}
func (p *Plexams) GetWorkflow(ctx context.Context) ([]*model.Step, error) {
return p.workflow, nil
}
func (p *Plexams) NextDeadline(ctx context.Context) (*model.Step, error) {
for _, step := range p.workflow {
if !step.Done && step.Deadline.Unix() > 0 {
return step, nil
}
}
return nil, nil
}
func (p *Plexams) PrintWorkflow() {
for _, step := range p.workflow {
if step.Done {
color.Green.Printf("%2d. %s", step.Number, step.Name)
} else {
color.Red.Printf("%2d. %s", step.Number, step.Name)
if step.Deadline.Unix() > 0 {
color.Yellow.Printf(" (Deadline %s)", step.Deadline.Format("02.01.06"))
}
}
color.Println()
}
}