8000 Allow an empty config file (#255) · stern/stern@c76ea87 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit c76ea87

Browse files
author
Takashi Kusumi
authored
Allow an empty config file (#255)
1 parent 2fdc298 commit c76ea87

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

cmd/cmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"encoding/json"
2020
goflag "flag"
2121
"fmt"
22+
"io"
2223
"os"
2324
"regexp"
2425
"strconv"
@@ -321,7 +322,7 @@ func (o *options) overrideFlagSetDefaultFromConfig(fs *pflag.FlagSet) error {
321322

322323
data := make(map[string]interface{})
323324

324-
if err := yaml.NewDecoder(configFile).Decode(data); err != nil {
325+
if err := yaml.NewDecoder(configFile).Decode(data); err != nil && err != io.EOF {
325326
return err
326327
}
327328

cmd/cmd_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,12 @@ func TestOptionsOverrideFlagSetDefaultFromConfig(t *testing.T) {
812812
expectedTailValue: 1,
813813
wantErr: false,
814814
},
815+
{
816+
name: "--config=testdata/config-empty.yaml",
817+
flagConfigFilePathValue: filepath.Join(wd, "testdata/config-empty.yaml"),
818+
expectedTailValue: -1,
819+
wantErr: false,
820+
},
815821
{
816822
name: "--config=config-not-exist.yaml",
817823
flagConfigFilePathValue: filepath.Join(wd, "config-not-exist.yaml"),

cmd/testdata/config-empty.yaml

Whitespace-only changes.

0 commit comments

Comments
 (0)
0