Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support yml extension #39

Merged
merged 3 commits into from
Nov 14, 2024
Merged

Support yml extension #39

merged 3 commits into from
Nov 14, 2024

Conversation

gbonnefille
Copy link

The .yml is a common variation of the .yaml extension.

Guilhem Bonnefille added 2 commits October 15, 2024 15:45
The .yml is a common variation of the .yaml extension.
@rykov
Copy link
Owner

rykov commented Oct 31, 2024

@gbonnefille Looks good, however, as they are private, I don't see a reason to keep both walkFilesByExts and walkFilesByExt. So why not do something like this to avoid walking the filesystem multiple times:

func (fs *Fs) walkFilesByExts(dir string, exts []string, walkFn func(path, key string, fi os.FileInfo, err error)) error {
  return afero.Walk(fs, dir, func(path string, fi os.FileInfo, err error) error {
    if err != nil || fi.IsDir() {
      return nil
    }

    pathExt := filepath.Ext(path)
    if !slices.Contains(exts, pathExt) {
      return nil
    }

    // Remove dir prefix and extension
    key, _ := filepath.Rel(dir, path)
    key = key[:len(key)-len(pathExt)]
    walkFn(path, key, fi, nil)
    return nil
  })
}

Keeping a single implementation avoid walking the filesystem multiple times.
@gbonnefille
Copy link
Author

I applied your suggestion

@rykov rykov merged commit 2fe3ddd into rykov:main Nov 14, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants