-
Notifications
You must be signed in to change notification settings - Fork 74
/
status.go
91 lines (76 loc) · 1.86 KB
/
status.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
82
83
84
85
86
87
88
89
90
91
package cmd
import (
"context"
"encoding/json"
"fmt"
"github.com/testground/testground/pkg/api"
"github.com/testground/testground/pkg/client"
"github.com/testground/testground/pkg/data"
"github.com/testground/testground/pkg/task"
"github.com/urfave/cli/v2"
)
var StatusCommand = cli.Command{
Name: "status",
Usage: "get the current status for a certain task",
Action: statusCommand,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "extended",
Usage: "print extended information such as input and results",
},
&cli.StringFlag{
Name: "task",
Aliases: []string{"t"},
Usage: "the task id",
Required: true,
},
},
}
func statusCommand(c *cli.Context) error {
ctx, cancel := context.WithCancel(ProcessContext())
defer cancel()
id := c.String("task")
cl, _, err := setupClient(c)
if err != nil {
return err
}
r, err := cl.Status(ctx, &api.StatusRequest{TaskID: id})
if err != nil {
return err
}
defer r.Close()
res, err := client.ParseStatusResponse(r, c.App.Writer)
if err != nil {
return err
}
printTask(res)
if c.Bool("extended") {
fmt.Printf("\nInput:\n")
input, err := json.Marshal(res.Input)
if err != nil {
return err
}
fmt.Println(string(input))
fmt.Printf("\nResult:\n")
output, err := json.Marshal(res.Result)
if err != nil {
return err
}
fmt.Println(string(output))
}
return nil
}
func printTask(tsk task.Task) {
outcome, err := data.DecodeTaskOutcome(&tsk)
outcomeStr := string(outcome)
if err != nil {
outcomeStr = fmt.Sprintf("failed to decode task outcome: %v", err)
}
fmt.Printf("ID:\t\t%s\n", tsk.ID)
fmt.Printf("Priority:\t%d\n", tsk.Priority)
fmt.Printf("Created:\t%s\n", tsk.Created())
fmt.Printf("Type:\t\t%s\n", tsk.Type)
fmt.Printf("Status:\t\t%s\n", tsk.State().State)
fmt.Printf("Outcome:\t%s\n", outcomeStr)
fmt.Printf("Last update:\t%s\n", tsk.State().Created)
}