Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions internal/tiger/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ func buildServiceForkCmd() *cobra.Command {
var forkWaitTimeout time.Duration
var forkNow bool
var forkLastSnapshot bool
var forkToTimestamp string
var forkToTimestamp time.Time
var forkCPU int
var forkMemory int
var forkWithPassword bool
Expand Down Expand Up @@ -1142,6 +1142,7 @@ Examples:

# Fork with custom wait timeout
tiger service fork svc-12345 --now --wait-timeout 45m`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// Validate timing flags first - exactly one must be specified
timingFlagsSet := 0
Expand All @@ -1151,7 +1152,8 @@ Examples:
if forkLastSnapshot {
timingFlagsSet++
}
if forkToTimestamp != "" {
toTimestampSet := cmd.Flags().Changed("to-timestamp")
if toTimestampSet {
timingFlagsSet++
}

Expand All @@ -1162,14 +1164,6 @@ Examples:
return fmt.Errorf("can only specify one of --now, --last-snapshot or --to-timestamp")
}

// Validate timestamp format early if --to-timestamp is used
if forkToTimestamp != "" {
_, err := time.Parse(time.RFC3339, forkToTimestamp)
if err != nil {
return fmt.Errorf("invalid timestamp format '%s'. Use RFC3339 format (e.g., 2025-01-15T10:30:00Z): %w", forkToTimestamp, err)
}
}

// Get config
cfg, err := config.Load()
if err != nil {
Expand Down Expand Up @@ -1237,9 +1231,9 @@ Examples:
forkStrategy = api.NOW
} else if forkLastSnapshot {
forkStrategy = api.LASTSNAPSHOT
} else if forkToTimestamp != "" {
} else if toTimestampSet {
forkStrategy = api.PITR
parsedTime, _ := time.Parse(time.RFC3339, forkToTimestamp) // Already validated above
parsedTime := forkToTimestamp
targetTime = &parsedTime
}

Expand Down Expand Up @@ -1361,7 +1355,7 @@ Examples:
// Timing strategy flags
cmd.Flags().BoolVar(&forkNow, "now", false, "Fork at the current database state (creates new snapshot or uses WAL replay)")
cmd.Flags().BoolVar(&forkLastSnapshot, "last-snapshot", false, "Fork at the last existing snapshot (faster)")
cmd.Flags().StringVar(&forkToTimestamp, "to-timestamp", "", "Fork at a specific point in time (RFC3339 format, e.g., 2025-01-15T10:30:00Z)")
cmd.Flags().TimeVar(&forkToTimestamp, "to-timestamp", time.Time{}, []string{time.RFC3339}, "Fork at a specific point in time (RFC3339 format, e.g., 2025-01-15T10:30:00Z)")

// Resource customization flags
cmd.Flags().IntVar(&forkCPU, "cpu", 0, "CPU allocation in millicores (inherits from source if not specified)")
Expand Down
2 changes: 1 addition & 1 deletion internal/tiger/cmd/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func TestServiceFork_InvalidTimestamp(t *testing.T) {
t.Fatal("Expected error when invalid timestamp provided")
}

if !strings.Contains(err.Error(), "invalid timestamp format") {
if !strings.Contains(err.Error(), "invalid time format") {
t.Errorf("Expected invalid timestamp error, got: %v", err)
}
}
Expand Down