(cmd *cobra.Command, _ []string)
| 54 | } |
| 55 | |
| 56 | func runTasksList(cmd *cobra.Command, _ []string) error { |
| 57 | session, err := initCLISession(cmd) |
| 58 | if err != nil { |
| 59 | return printError(err) |
| 60 | } |
| 61 | |
| 62 | if session == nil { |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | recent, _ := cmd.Flags().GetInt("recent") |
| 67 | |
| 68 | tasks, err := session.getTasks(context.Background()) |
| 69 | if err != nil { |
| 70 | return printError(fmt.Errorf("failed to fetch tasks: %w", err)) |
| 71 | } |
| 72 | |
| 73 | // Apply limit. |
| 74 | if recent > 0 && len(tasks) > recent { |
| 75 | tasks = tasks[:recent] |
| 76 | } |
| 77 | |
| 78 | out := make([]taskOutput, 0, len(tasks)) |
| 79 | for _, t := range tasks { |
| 80 | if t == nil { |
| 81 | continue |
| 82 | } |
| 83 | |
| 84 | out = append(out, taskOutput{ |
| 85 | UPID: t.UPID, |
| 86 | Node: t.Node, |
| 87 | Type: t.Type, |
| 88 | Status: t.Status, |
| 89 | User: t.User, |
| 90 | StartTime: t.StartTime, |
| 91 | EndTime: t.EndTime, |
| 92 | SourceProfile: t.SourceProfile, |
| 93 | }) |
| 94 | } |
| 95 | |
| 96 | if getOutputFormat(cmd) == outputTable { |
| 97 | headers := []string{"NODE", "TYPE", "STATUS", "USER", "STARTED", "UPID"} |
| 98 | rows := make([][]string, 0, len(out)) |
| 99 | |
| 100 | for _, t := range out { |
| 101 | rows = append(rows, []string{ |
| 102 | t.Node, |
| 103 | t.Type, |
| 104 | t.Status, |
| 105 | t.User, |
| 106 | formatUnixTime(t.StartTime), |
| 107 | t.UPID, |
| 108 | }) |
| 109 | } |
| 110 | |
| 111 | printTable(headers, rows) |
| 112 | |
| 113 | return nil |
nothing calls this directly
no test coverage detected