Skip to content

Commit 3f65bd1

Browse files
authored
fix: ignore surronding whitespace for cli config (#12250)
* fix: ignore surronding whitespace for cli config Cli config files break if you edit them manually with any editor. Editors drop a newline at the end, and we not break on this. If a developer manually edits a file, it should still work
1 parent 475c365 commit 3f65bd1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cli/config/file.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"io"
55
"os"
66
"path/filepath"
7+
"strings"
78

89
"github.com/kirsle/configdir"
910
"golang.org/x/xerrors"
@@ -85,13 +86,14 @@ func (f File) Write(s string) error {
8586
return write(string(f), 0o600, []byte(s))
8687
}
8788

88-
// Read reads the file to a string.
89+
// Read reads the file to a string. All leading and trailing whitespace
90+
// is removed.
8991
func (f File) Read() (string, error) {
9092
if f == "" {
9193
return "", xerrors.Errorf("empty file path")
9294
}
9395
byt, err := read(string(f))
94-
return string(byt), err
96+
return strings.TrimSpace(string(byt)), err
9597
}
9698

9799
// open opens a file in the configuration directory,

0 commit comments

Comments
 (0)