Skip to content

Commit

Permalink
support for tidle in name
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanCoughlan5 committed Jan 10, 2025
1 parent 3a8b883 commit e18c32d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
8 changes: 7 additions & 1 deletion cmd/createSnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/Layr-Labs/sidecar/internal/config"
"github.com/Layr-Labs/sidecar/internal/logger"
"github.com/Layr-Labs/sidecar/pkg/snapshot"
"github.com/Layr-Labs/sidecar/pkg/utils"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand All @@ -24,8 +25,13 @@ var createSnapshotCmd = &cobra.Command{
return fmt.Errorf("failed to initialize logger: %w", err)
}

outputFile, err := utils.ExpandHomeDir(cfg.SnapshotConfig.OutputFile)
if err != nil {
return err
}

svc := snapshot.NewSnapshotService(&snapshot.SnapshotConfig{
OutputFile: cfg.SnapshotConfig.OutputFile,
OutputFile: outputFile,
Host: cfg.DatabaseConfig.Host,
Port: cfg.DatabaseConfig.Port,
User: cfg.DatabaseConfig.User,
Expand Down
8 changes: 7 additions & 1 deletion cmd/restoreSnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/Layr-Labs/sidecar/internal/config"
"github.com/Layr-Labs/sidecar/internal/logger"
"github.com/Layr-Labs/sidecar/pkg/snapshot"
"github.com/Layr-Labs/sidecar/pkg/utils"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand All @@ -25,8 +26,13 @@ The snapshot file is expected to be a pg_dump custom format file.`,
return fmt.Errorf("failed to initialize logger: %w", err)
}

inputFile, err := utils.ExpandHomeDir(cfg.SnapshotConfig.InputFile)
if err != nil {
return err
}

svc := snapshot.NewSnapshotService(&snapshot.SnapshotConfig{
InputFile: cfg.SnapshotConfig.InputFile,
InputFile: inputFile,
Host: cfg.DatabaseConfig.Host,
Port: cfg.DatabaseConfig.Port,
User: cfg.DatabaseConfig.User,
Expand Down
14 changes: 14 additions & 0 deletions pkg/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package utils
import (
"encoding/hex"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
)
Expand All @@ -24,3 +26,15 @@ func SnakeCase(s string) string {
notSnake := regexp.MustCompile(`[_-]`)
return notSnake.ReplaceAllString(s, "_")
}

// ExpandHomeDir expands the ~ in file paths to the user's home directory.
func ExpandHomeDir(path string) (string, error) {
if strings.HasPrefix(path, "~/") {
homeDir, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("failed to get user home directory: %w", err)
}
path = filepath.Join(homeDir, path[2:])
}
return path, nil
}

0 comments on commit e18c32d

Please sign in to comment.