(dataDir, daemonURL *string)
| 11 | ) |
| 12 | |
| 13 | func graphCmd(dataDir, daemonURL *string) *cobra.Command { |
| 14 | var runID string |
| 15 | var artifactRef string |
| 16 | var attemptID string |
| 17 | var toolCallID string |
| 18 | var processID string |
| 19 | openDB := func() (*sql.DB, error) { |
| 20 | paths, err := store.Init(*dataDir) |
| 21 | if err != nil { |
| 22 | return nil, err |
| 23 | } |
| 24 | db, err := store.Open(paths) |
| 25 | if err != nil { |
| 26 | return nil, err |
| 27 | } |
| 28 | return db, nil |
| 29 | } |
| 30 | trace := &cobra.Command{ |
| 31 | Use: "trace", |
| 32 | Short: "trace run or artifact provenance", |
| 33 | RunE: func(cmd *cobra.Command, args []string) error { |
| 34 | db, err := openDB() |
| 35 | if err != nil { |
| 36 | return err |
| 37 | } |
| 38 | defer db.Close() |
| 39 | selected := 0 |
| 40 | for _, value := range []string{runID, artifactRef, attemptID, toolCallID, processID} { |
| 41 | if value != "" { |
| 42 | selected++ |
| 43 | } |
| 44 | } |
| 45 | if selected > 1 { |
| 46 | return fmt.Errorf("use only one of --run, --artifact, --attempt, --tool-call, or --process") |
| 47 | } |
| 48 | if processID != "" { |
| 49 | return provenance.TraceProcess(db, processID, cmd.OutOrStdout()) |
| 50 | } |
| 51 | if toolCallID != "" { |
| 52 | return provenance.TraceToolCall(db, toolCallID, cmd.OutOrStdout()) |
| 53 | } |
| 54 | if attemptID != "" { |
| 55 | return provenance.TraceAttempt(db, attemptID, cmd.OutOrStdout()) |
| 56 | } |
| 57 | if artifactRef != "" { |
| 58 | return provenance.TraceArtifact(db, artifactRef, cmd.OutOrStdout()) |
| 59 | } |
| 60 | if runID != "" { |
| 61 | return provenance.TraceRun(db, runID, cmd.OutOrStdout()) |
| 62 | } |
| 63 | return fmt.Errorf("one of --run, --artifact, --attempt, --tool-call, or --process is required") |
| 64 | }, |
| 65 | } |
| 66 | trace.Flags().StringVar(&runID, "run", "", "run id") |
| 67 | trace.Flags().StringVar(&artifactRef, "artifact", "", "artifact result ref") |
| 68 | trace.Flags().StringVar(&attemptID, "attempt", "", "attempt id") |
| 69 | trace.Flags().StringVar(&toolCallID, "tool-call", "", "tool call id") |
| 70 | trace.Flags().StringVar(&processID, "process", "", "process id") |
no test coverage detected