Skip to content

Commit 9daafb7

Browse files
committed
feat: snapshot info
1 parent ded1ebf commit 9daafb7

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

cmd/snapshot.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,35 @@ Examples:
9090
}
9191
},
9292
}
93+
94+
snapshotInfoCmd = &cobra.Command{
95+
Use: "info",
96+
Short: "Display snapshot metadata",
97+
Long: `Display metadata about the current snapshot.
98+
99+
Shows the snapshot path, hash, size, creation time, and fixtures used.
100+
101+
Examples:
102+
regresql snapshot info`,
103+
Run: func(cmd *cobra.Command, args []string) {
104+
if err := checkDirectory(snapshotCwd); err != nil {
105+
fmt.Print(err.Error())
106+
os.Exit(1)
107+
}
108+
if err := runSnapshotInfo(); err != nil {
109+
fmt.Printf("Error: %s\n", err.Error())
110+
os.Exit(1)
111+
}
112+
},
113+
}
93114
)
94115

95116
func init() {
96117
RootCmd.AddCommand(snapshotCmd)
97118
snapshotCmd.AddCommand(snapshotCaptureCmd)
98119
snapshotCmd.AddCommand(snapshotRestoreCmd)
99120
snapshotCmd.AddCommand(snapshotBuildCmd)
121+
snapshotCmd.AddCommand(snapshotInfoCmd)
100122

101123
snapshotCmd.PersistentFlags().StringVarP(&snapshotCwd, "cwd", "C", ".", "Change to directory")
102124

@@ -349,3 +371,34 @@ func runSnapshotBuild() error {
349371

350372
return nil
351373
}
374+
375+
func runSnapshotInfo() error {
376+
snapshotsDir := regresql.GetSnapshotsDir(snapshotCwd)
377+
378+
metadata, err := regresql.ReadSnapshotMetadata(snapshotsDir)
379+
if err != nil {
380+
return fmt.Errorf("no snapshot metadata found. Run 'regresql snapshot build' or 'regresql snapshot capture' first")
381+
}
382+
383+
if metadata.Current == nil {
384+
return fmt.Errorf("snapshot metadata is empty")
385+
}
386+
387+
info := metadata.Current
388+
389+
fmt.Printf("Snapshot: %s\n", info.Path)
390+
fmt.Printf(" Format: %s\n", info.Format)
391+
fmt.Printf(" Size: %s\n", regresql.FormatBytes(info.SizeBytes))
392+
fmt.Printf(" Created: %s\n", info.Created.Format("2006-01-02 15:04:05 UTC"))
393+
fmt.Printf(" Hash: %s\n", info.Hash)
394+
395+
if len(info.FixturesUsed) > 0 {
396+
fmt.Println()
397+
fmt.Println("Fixtures used:")
398+
for _, f := range info.FixturesUsed {
399+
fmt.Printf(" - %s\n", f)
400+
}
401+
}
402+
403+
return nil
404+
}

0 commit comments

Comments
 (0)