-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
executable file
·45 lines (43 loc) · 923 Bytes
/
list.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
package command
import (
"fmt"
"github.com/songxinjianqwe/scheduler/cli/client"
"github.com/urfave/cli"
"os"
"text/tabwriter"
)
var ListCommand = cli.Command{
Name: "list",
Aliases: []string{"l"},
Usage: "list all tasks",
Action: func(c *cli.Context) error {
schedulerClient, err := client.NewClient()
if err != nil {
return err
}
tasks, err := schedulerClient.List()
if err != nil {
return err
}
if len(tasks) == 0 {
fmt.Println("no tasks")
return nil
}
// 表格式打印
w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
fmt.Fprint(w, "Id\tTaskType\tTime\tScript\tStatus\tLastStatusUpdated\n")
for _, item := range tasks {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n",
item.Id,
item.TaskType,
item.Time,
item.Script,
item.Status.String(),
item.LastStatusUpdated)
}
if err := w.Flush(); err != nil {
return err
}
return nil
},
}