Skip to content

Commit 382f421

Browse files
committed
feat: follow best practices with regards to naming .env files
Signed-off-by: Drake Evans <[email protected]>
1 parent 91b23ea commit 382f421

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

cmd/sops/formats/formats.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package formats
22

3-
import "strings"
3+
import (
4+
"path/filepath"
5+
"strings"
6+
)
47

58
// Format is an enum type
69
type Format int
@@ -43,7 +46,7 @@ func IsJSONFile(path string) bool {
4346

4447
// IsEnvFile returns true if a given file path corresponds to a .env file
4548
func IsEnvFile(path string) bool {
46-
return strings.HasSuffix(path, ".env")
49+
return strings.HasSuffix(path, ".env") || strings.HasPrefix(filepath.Base(path), ".env")
4750
}
4851

4952
// IsIniFile returns true if a given file path corresponds to a INI file

cmd/sops/formats/formats_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestFormatFromString(t *testing.T) {
1717
func TestFormatForPath(t *testing.T) {
1818
assert.Equal(t, Binary, FormatForPath("/path/to/foobar"))
1919
assert.Equal(t, Dotenv, FormatForPath("/path/to/foobar.env"))
20+
assert.Equal(t, Dotenv, FormatForPath("/path/to/.env.foobar"))
2021
assert.Equal(t, Ini, FormatForPath("/path/to/foobar.ini"))
2122
assert.Equal(t, Json, FormatForPath("/path/to/foobar.json"))
2223
assert.Equal(t, Yaml, FormatForPath("/path/to/foobar.yml"))
@@ -27,6 +28,7 @@ func TestFormatForPathOrString(t *testing.T) {
2728
assert.Equal(t, Binary, FormatForPathOrString("/path/to/foobar", ""))
2829
assert.Equal(t, Dotenv, FormatForPathOrString("/path/to/foobar", "dotenv"))
2930
assert.Equal(t, Dotenv, FormatForPathOrString("/path/to/foobar.env", ""))
31+
assert.Equal(t, Dotenv, FormatForPathOrString("/path/to/.env.foobar", ""))
3032
assert.Equal(t, Ini, FormatForPathOrString("/path/to/foobar", "ini"))
3133
assert.Equal(t, Ini, FormatForPathOrString("/path/to/foobar.ini", ""))
3234
assert.Equal(t, Json, FormatForPathOrString("/path/to/foobar", "json"))

0 commit comments

Comments
 (0)