mirror of https://github.com/coder/coder.git
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
This commit is contained in:
parent
475c3650ca
commit
3f65bd14cc
|
@ -4,6 +4,7 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/kirsle/configdir"
|
||||
"golang.org/x/xerrors"
|
||||
|
@ -85,13 +86,14 @@ func (f File) Write(s string) error {
|
|||
return write(string(f), 0o600, []byte(s))
|
||||
}
|
||||
|
||||
// Read reads the file to a string.
|
||||
// Read reads the file to a string. All leading and trailing whitespace
|
||||
// is removed.
|
||||
func (f File) Read() (string, error) {
|
||||
if f == "" {
|
||||
return "", xerrors.Errorf("empty file path")
|
||||
}
|
||||
byt, err := read(string(f))
|
||||
return string(byt), err
|
||||
return strings.TrimSpace(string(byt)), err
|
||||
}
|
||||
|
||||
// open opens a file in the configuration directory,
|
||||
|
|
Loading…
Reference in New Issue