Skip to content

Commit

Permalink
Allow an empty config file (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
tksm committed Apr 11, 2023
1 parent 2fdc298 commit c76ea87
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
goflag "flag"
"fmt"
"io"
"os"
"regexp"
"strconv"
Expand Down Expand Up @@ -321,7 +322,7 @@ func (o *options) overrideFlagSetDefaultFromConfig(fs *pflag.FlagSet) error {

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

if err := yaml.NewDecoder(configFile).Decode(data); err != nil {
if err := yaml.NewDecoder(configFile).Decode(data); err != nil && err != io.EOF {
return err
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,12 @@ func TestOptionsOverrideFlagSetDefaultFromConfig(t *testing.T) {
expectedTailValue: 1,
wantErr: false,
},
{
name: "--config=testdata/config-empty.yaml",
flagConfigFilePathValue: filepath.Join(wd, "testdata/config-empty.yaml"),
expectedTailValue: -1,
wantErr: false,
},
{
name: "--config=config-not-exist.yaml",
flagConfigFilePathValue: filepath.Join(wd, "config-not-exist.yaml"),
Expand Down
Empty file added cmd/testdata/config-empty.yaml
Empty file.

0 comments on commit c76ea87

Please sign in to comment.