(args []string)
| 809 | } |
| 810 | |
| 811 | func listRunsCmd(args []string) int { |
| 812 | fs := flagSet("list runs") |
| 813 | status := fs.String("status", "", "backlog|in-progress|done") |
| 814 | includeArchived := fs.Bool("include-archived", false, "include archived") |
| 815 | opts := addListFlags(fs) |
| 816 | if err := fs.Parse(args); err != nil { |
| 817 | return 2 |
| 818 | } |
| 819 | fmtKind, err := listfmt.ParseFormat(*opts.format) |
| 820 | if err != nil { |
| 821 | fmt.Fprintf(os.Stderr, "error: %v\n", err) |
| 822 | return 2 |
| 823 | } |
| 824 | var playbookSlug string |
| 825 | if fs.NArg() > 0 { |
| 826 | playbookSlug = fs.Arg(0) |
| 827 | } |
| 828 | |
| 829 | dbPath, err := flowDBPath() |
| 830 | if err != nil { |
| 831 | fmt.Fprintf(os.Stderr, "error: %v\n", err) |
| 832 | return 1 |
| 833 | } |
| 834 | db, err := flowdb.OpenDB(dbPath) |
| 835 | if err != nil { |
| 836 | fmt.Fprintf(os.Stderr, "error: %v\n", err) |
| 837 | return 1 |
| 838 | } |
| 839 | defer db.Close() |
| 840 | |
| 841 | tasks, err := flowdb.ListTasks(db, flowdb.TaskFilter{ |
| 842 | Kind: "playbook_run", |
| 843 | PlaybookSlug: playbookSlug, |
| 844 | Status: *status, |
| 845 | IncludeArchived: *includeArchived, |
| 846 | }) |
| 847 | if err != nil { |
| 848 | fmt.Fprintf(os.Stderr, "error: %v\n", err) |
| 849 | return 1 |
| 850 | } |
| 851 | |
| 852 | headers := []string{"STATUS", "SLUG", "PLAYBOOK", "NOTES"} |
| 853 | tsvHeaders := []string{"slug", "status", "playbook", "archived"} |
| 854 | if len(tasks) == 0 { |
| 855 | return emptyResult(fmtKind, "runs", tsvHeaders) |
| 856 | } |
| 857 | |
| 858 | type runRow struct { |
| 859 | Slug string `json:"slug"` |
| 860 | Status string `json:"status"` |
| 861 | Playbook string `json:"playbook,omitempty"` |
| 862 | Archived bool `json:"archived,omitempty"` |
| 863 | } |
| 864 | rows := make([]runRow, len(tasks)) |
| 865 | for i, tk := range tasks { |
| 866 | r := runRow{Slug: tk.Slug, Status: tk.Status, Archived: tk.ArchivedAt.Valid} |
| 867 | if tk.PlaybookSlug.Valid { |
| 868 | r.Playbook = tk.PlaybookSlug.String |
no test coverage detected