| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "flag" |
| 6 | "fmt" |
| 7 | "os" |
| 8 | "path/filepath" |
| 9 | "strings" |
| 10 | |
| 11 | "reasonix/internal/taskcatalog" |
| 12 | ) |
| 13 | |
| 14 | func init() { |
| 15 | registerCatalogCommand(catalogCommand{ |
| 16 | name: "tasks", path: taskcatalog.DefaultPath, reindex: reindexTaskCatalog, |
| 17 | completionFlags: []cliCompletionFlag{ |
| 18 | completionFlag("--json", cliCompletionNoValue), |
| 19 | completionFlag("--project", cliCompletionPathValue), |
| 20 | }, |
| 21 | }) |
| 22 | } |
| 23 | |
| 24 | func reindexTaskCatalog(args []string) int { |
| 25 | fs := flag.NewFlagSet("catalogs reindex tasks", flag.ContinueOnError) |
| 26 | var projects stringListFlag |
| 27 | jsonOut := fs.Bool("json", false, "print status as JSON") |
| 28 | fs.Var(&projects, "project", "project root to index; repeat for multiple projects") |
| 29 | if code, ok := parseCommandFlags(fs, args); !ok { |
| 30 | return code |
| 31 | } |
| 32 | if len(projects) == 0 { |
| 33 | for _, target := range defaultSessionCatalogTargets() { |
| 34 | if strings.TrimSpace(target.WorkspaceRoot) != "" { |
| 35 | projects = append(projects, target.WorkspaceRoot) |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | items := make([]taskcatalog.Project, 0, len(projects)) |
| 40 | for _, root := range projects { |
| 41 | items = append(items, taskcatalog.Project{Root: root, Label: filepath.Base(root)}) |
| 42 | } |
| 43 | status, err := taskcatalog.Rebuild(context.Background(), "", items) |
| 44 | if err != nil { |
| 45 | fmt.Fprintln(os.Stderr, "error:", err) |
| 46 | return 1 |
| 47 | } |
| 48 | return printCatalogStatus(status, *jsonOut) |
| 49 | } |
| 50 |