Skip to content

Commit

Permalink
Merge pull request #5 from askolesov/sidecars-fix
Browse files Browse the repository at this point in the history
Fix sidecar processing and default config
  • Loading branch information
askolesov authored Oct 24, 2024
2 parents 111c371 + 3ca2fd3 commit 93c73c6
Show file tree
Hide file tree
Showing 19 changed files with 32 additions and 32 deletions.
18 changes: 9 additions & 9 deletions pkg/command/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func addFiles(cmd *cobra.Command, addPath string, dryRun, errorOnAction bool) er
}

// Load config
cfg, err := util.ReadConfigFromFile(DefaultConfigFile)
cfg, err := vault.ReadConfigFromFile(DefaultConfigFile)
if err != nil {
return err
}
Expand All @@ -78,7 +78,7 @@ func addFiles(cmd *cobra.Command, addPath string, dryRun, errorOnAction bool) er

pw.AppendTracker(tracker)

inFilesRel, err := util.ListFilesRel(pw.Log, addPath, tracker.Increment, cfg.SkipPermissionDenied)
inFilesRel, err := vault.ListFilesRel(pw.Log, addPath, tracker.Increment, cfg.SkipPermissionDenied)
if err != nil {
return err
}
Expand All @@ -94,15 +94,15 @@ func addFiles(cmd *cobra.Command, addPath string, dryRun, errorOnAction bool) er

pw.AppendTracker(tracker)

inFilesRel = util.FilterIgnore(inFilesRel, cfg.Ignore, tracker.Increment)
inFilesRel = vault.FilterIgnore(inFilesRel, cfg.Ignore, tracker.Increment)

tracker.MarkAsDone()

// 3. Link sidecar files

pw.Log("Linking sidecar files")

inFilesRelLinked := util.LinkSidecars(cfg.SidecarExtensions, inFilesRel)
inFilesRelLinked := vault.LinkSidecars(cfg.SidecarExtensions, inFilesRel)

// 4. Shuffle files

Expand Down Expand Up @@ -130,17 +130,17 @@ func addFiles(cmd *cobra.Command, addPath string, dryRun, errorOnAction bool) er

for _, f := range inFilesRelLinked {
// Copy main file
info, err := util.ExtractMetadata(et, addPath, f.Path)
info, err := vault.ExtractMetadata(et, addPath, f.Path)
if err != nil {
return fmt.Errorf("failed to extract metadata for %s: %w", f.Path, err)
}

targetPath, err := util.RenderTemplate(cfg.Template, info)
targetPath, err := vault.RenderTemplate(cfg.Template, info)
if err != nil {
return fmt.Errorf("failed to render template for %s: %w", f.Path, err)
}

err = util.SmartCopyFile(
err = vault.SmartCopyFile(
pw.Log,
path.Join(addPath, f.Path),
path.Join(libPath, targetPath),
Expand All @@ -155,9 +155,9 @@ func addFiles(cmd *cobra.Command, addPath string, dryRun, errorOnAction bool) er
for _, sidecar := range f.Sidecars {
// Use the same name as the main file, but with the sidecar extension
sidecarPath := replaceExtension(targetPath, filepath.Ext(sidecar))
err = util.SmartCopyFile(
err = vault.SmartCopyFile(
pw.Log,
path.Join(addPath, sidecarPath),
path.Join(addPath, sidecar),
path.Join(libPath, sidecarPath),
dryRun,
errorOnAction,
Expand Down
2 changes: 1 addition & 1 deletion pkg/command/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func showFileInfo(cmd *cobra.Command, target string) error {
return err
}

infos, err := util.ExtractMetadata(et, dir, target)
infos, err := vault.ExtractMetadata(et, dir, target)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetInitCmd() *cobra.Command {
}

func ensureLibraryInitialized(cmd *cobra.Command) error {
cfgExists, err := util.IsConfigExists(DefaultConfigFile)
cfgExists, err := vault.IsConfigExists(DefaultConfigFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -75,7 +75,7 @@ func initLibrary(cmd *cobra.Command) error {
}

// Write default config to file
err = util.WriteDefaultConfigToFile(DefaultConfigFile)
err = vault.WriteDefaultConfigToFile(DefaultConfigFile)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/compare.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/compare_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"os"
Expand Down
8 changes: 4 additions & 4 deletions pkg/vault/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"encoding/json"
Expand Down Expand Up @@ -43,9 +43,9 @@ ignore:
# sidecarExtensions: List of file extensions for sidecar files.
sidecarExtensions:
- "*.xmp"
- "*.yaml"
- "*.json"
- ".xmp"
- ".yaml"
- ".json"
`
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/config_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/copy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/copy_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/filter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
ignore "github.com/sabhiram/go-gitignore"
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/filter_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/list_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/metadata.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"crypto/md5"
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/metadata_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"testing"
Expand Down
4 changes: 2 additions & 2 deletions pkg/vault/sidecar.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"path/filepath"
Expand All @@ -18,7 +18,7 @@ func LinkSidecars(
) []FileWithSidecars {
// helper functions

sidecarExts := lo.Associate(sidecarExtensions, func(item string) (string, any) {
sidecarExts := lo.Associate(sidecarExtensions, func(item string) (string, bool) {
return strings.ToLower(item), true
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/sidecar_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/template.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/template_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package vault

import (
"testing"
Expand Down

0 comments on commit 93c73c6

Please sign in to comment.