| 31 | } |
| 32 | |
| 33 | func runSessionList(args []string) error { |
| 34 | a := newOcrFlagSet("ocr session list") |
| 35 | var repoDir string |
| 36 | var asJSON bool |
| 37 | var limit int |
| 38 | a.StringVar(&repoDir, "repo", "", "root directory of the git repository (default: current dir)") |
| 39 | a.BoolVar(&asJSON, "json", false, "emit JSON instead of a table") |
| 40 | a.IntVar(&limit, "limit", 20, "cap the number of listed sessions (0 = unlimited)") |
| 41 | if err := a.Parse(args); err != nil { |
| 42 | return err |
| 43 | } |
| 44 | if a.showHelp { |
| 45 | printSessionListUsage() |
| 46 | return nil |
| 47 | } |
| 48 | |
| 49 | resolvedRepo, err := resolveWorkingDirForSession(repoDir) |
| 50 | if err != nil { |
| 51 | return err |
| 52 | } |
| 53 | summaries, err := session.ListSessions(resolvedRepo) |
| 54 | if err != nil { |
| 55 | return fmt.Errorf("list sessions: %w", err) |
| 56 | } |
| 57 | if limit > 0 && len(summaries) > limit { |
| 58 | summaries = summaries[:limit] |
| 59 | } |
| 60 | |
| 61 | if asJSON { |
| 62 | enc := json.NewEncoder(os.Stdout) |
| 63 | enc.SetIndent("", " ") |
| 64 | return enc.Encode(summaries) |
| 65 | } |
| 66 | |
| 67 | if len(summaries) == 0 { |
| 68 | fmt.Printf("No sessions found for %s\n", resolvedRepo) |
| 69 | return nil |
| 70 | } |
| 71 | printSessionTable(os.Stdout, summaries) |
| 72 | return nil |
| 73 | } |
| 74 | |
| 75 | func runSessionShow(args []string) error { |
| 76 | a := newOcrFlagSet("ocr session show") |