| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "flag" |
| 6 | "fmt" |
| 7 | "os" |
| 8 | |
| 9 | "reasonix/internal/config" |
| 10 | "reasonix/internal/usagecatalog" |
| 11 | ) |
| 12 | |
| 13 | func init() { |
| 14 | registerCatalogCommand(catalogCommand{ |
| 15 | name: "usage", path: usagecatalog.DefaultPath, reindex: reindexUsageCatalog, |
| 16 | completionFlags: []cliCompletionFlag{completionFlag("--json", cliCompletionNoValue)}, |
| 17 | }) |
| 18 | } |
| 19 | |
| 20 | func reindexUsageCatalog(args []string) int { |
| 21 | fs := flag.NewFlagSet("catalogs reindex usage", flag.ContinueOnError) |
| 22 | jsonOut := fs.Bool("json", false, "print status as JSON") |
| 23 | if code, ok := parseCommandFlags(fs, args); !ok { |
| 24 | return code |
| 25 | } |
| 26 | status, err := usagecatalog.Rebuild(context.Background(), "", config.StatsDir()) |
| 27 | if err != nil { |
| 28 | fmt.Fprintln(os.Stderr, "error:", err) |
| 29 | return 1 |
| 30 | } |
| 31 | return printCatalogStatus(status, *jsonOut) |
| 32 | } |
| 33 |