package app import ( "context" "flag" "fmt" "io" "sort" "gitea.maximumdirect.net/eric/narratio/internal/manifest" ) // Status reads and prints stage statuses from an existing manifest. func Status(ctx context.Context, args []string, out io.Writer) error { fs := flag.NewFlagSet("status", flag.ContinueOnError) fs.SetOutput(io.Discard) var manifestPath string fs.StringVar(&manifestPath, "manifest", "", "path to manifest.json") if err := fs.Parse(args); err != nil { return fmt.Errorf("status: invalid flags: %w", err) } if fs.NArg() != 0 { return fmt.Errorf("status: unexpected positional arguments") } if manifestPath == "" { return fmt.Errorf("status: --manifest is required") } store := &manifest.LocalStore{} m, err := store.Load(ctx, manifestPath) if err != nil { return fmt.Errorf("status: %w", err) } if _, err := fmt.Fprintf(out, "session_id: %s\n", m.SessionID); err != nil { return err } if _, err := fmt.Fprintf(out, "updated_at: %s\n", m.UpdatedAt.UTC().Format("2006-01-02T15:04:05Z07:00")); err != nil { return err } if len(m.Stages) == 0 { _, err := fmt.Fprintln(out, "stages: no stages recorded") return err } if _, err := fmt.Fprintln(out, "stages:"); err != nil { return err } names := make([]string, 0, len(m.Stages)) for name := range m.Stages { names = append(names, name) } sort.Strings(names) for _, name := range names { status := m.Stages[name].Status if _, err := fmt.Fprintf(out, "- %s: %s\n", name, status); err != nil { return err } } return nil }