Skip to content

Commit

Permalink
Add godoc, remove unused parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Nov 9, 2023
1 parent c389f27 commit 222173e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmd/algocfg/profileCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var printProfileCmd = &cobra.Command{
if err != nil {
reportErrorf("%v", err)

Check warning on line 144 in cmd/algocfg/profileCommand.go

View check run for this annotation

Codecov / codecov/patch

cmd/algocfg/profileCommand.go#L141-L144

Added lines #L141 - L144 were not covered by tests
}
err = codecs.WriteNonDefaultValues(os.Stdout, cfg, config.GetDefaultLocal(), nil, true)
err = codecs.WriteNonDefaultValues(os.Stdout, cfg, config.GetDefaultLocal(), nil)
if err != nil {
reportErrorf("Error writing config file to stdout: %s", err)

Check warning on line 148 in cmd/algocfg/profileCommand.go

View check run for this annotation

Codecov / codecov/patch

cmd/algocfg/profileCommand.go#L146-L148

Added lines #L146 - L148 were not covered by tests
}
Expand Down Expand Up @@ -175,7 +175,7 @@ var setProfileCmd = &cobra.Command{
return
}
}
err = codecs.SaveNonDefaultValuesToFile(file, cfg, config.GetDefaultLocal(), nil, true)
err = codecs.SaveNonDefaultValuesToFile(file, cfg, config.GetDefaultLocal(), nil)

Check warning on line 178 in cmd/algocfg/profileCommand.go

View check run for this annotation

Codecov / codecov/patch

cmd/algocfg/profileCommand.go#L178

Added line #L178 was not covered by tests
if err != nil {
reportErrorf("Error saving updated config file '%s' - %s", file, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/algocfg/resetCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var resetCmd = &cobra.Command{
}

file := filepath.Join(dataDir, config.ConfigFilename)
err = codecs.SaveNonDefaultValuesToFile(file, cfg, defaults, nil, true)
err = codecs.SaveNonDefaultValuesToFile(file, cfg, defaults, nil)

Check warning on line 66 in cmd/algocfg/resetCommand.go

View check run for this annotation

Codecov / codecov/patch

cmd/algocfg/resetCommand.go#L66

Added line #L66 was not covered by tests
if err != nil {
reportWarnf("Error saving updated config file '%s' - %s", file, err)
anyError = true
Expand Down
2 changes: 1 addition & 1 deletion cmd/algocfg/setCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var setCmd = &cobra.Command{
}

file := filepath.Join(dataDir, config.ConfigFilename)
err = codecs.SaveNonDefaultValuesToFile(file, cfg, config.GetDefaultLocal(), nil, true)
err = codecs.SaveNonDefaultValuesToFile(file, cfg, config.GetDefaultLocal(), nil)

Check warning on line 69 in cmd/algocfg/setCommand.go

View check run for this annotation

Codecov / codecov/patch

cmd/algocfg/setCommand.go#L69

Added line #L69 was not covered by tests
if err != nil {
reportWarnf("Error saving updated config file '%s' - %s", file, err)
anyError = true
Expand Down
2 changes: 1 addition & 1 deletion config/localTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ func (cfg Local) SaveAllToDisk(root string) error {
func (cfg Local) SaveToFile(filename string) error {
var alwaysInclude []string
alwaysInclude = append(alwaysInclude, "Version")
return codecs.SaveNonDefaultValuesToFile(filename, cfg, defaultLocal, alwaysInclude, true)
return codecs.SaveNonDefaultValuesToFile(filename, cfg, defaultLocal, alwaysInclude)
}

// DNSSecuritySRVEnforced returns true if SRV response verification enforced
Expand Down
9 changes: 6 additions & 3 deletions util/codecs/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func SaveObjectToFile(filename string, object interface{}, prettyFormat bool) er
return writeBytes(f, object, prettyFormat)

Check warning on line 69 in util/codecs/json.go

View check run for this annotation

Codecov / codecov/patch

util/codecs/json.go#L69

Added line #L69 was not covered by tests
}

func WriteNonDefaultValues(writer io.Writer, object, defaultObject interface{}, ignore []string, prettyFormat bool) error {
// WriteNonDefaultValues writes object to a writer as json, but only fields that are not
// currently set to be the default value.
// Optionally, you can specify an array of field names to always include.
func WriteNonDefaultValues(writer io.Writer, object, defaultObject interface{}, ignore []string) error {

Check warning on line 75 in util/codecs/json.go

View check run for this annotation

Codecov / codecov/patch

util/codecs/json.go#L75

Added line #L75 was not covered by tests
// Iterate one line at a time, parse Name
// If ignore contains Name, don't delete
// Use reflection to compare object[Name].value == defaultObject[Name].value
Expand Down Expand Up @@ -151,15 +154,15 @@ func WriteNonDefaultValues(writer io.Writer, object, defaultObject interface{},
// SaveNonDefaultValuesToFile saves an object to a file as json, but only fields that are not
// currently set to be the default value.
// Optionally, you can specify an array of field names to always include.
func SaveNonDefaultValuesToFile(filename string, object, defaultObject interface{}, ignore []string, prettyFormat bool) error {
func SaveNonDefaultValuesToFile(filename string, object, defaultObject interface{}, ignore []string) error {

Check warning on line 157 in util/codecs/json.go

View check run for this annotation

Codecov / codecov/patch

util/codecs/json.go#L157

Added line #L157 was not covered by tests
outFile, err := os.Create(filename)
if err != nil {
return err
}
defer outFile.Close()
writer := bufio.NewWriter(outFile)

WriteNonDefaultValues(writer, object, defaultObject, ignore, prettyFormat)
WriteNonDefaultValues(writer, object, defaultObject, ignore)

Check failure on line 165 in util/codecs/json.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 Error return value is not checked (errcheck) Raw Output: util/codecs/json.go:165:23: Error return value is not checked (errcheck) WriteNonDefaultValues(writer, object, defaultObject, ignore) ^

Check warning on line 165 in util/codecs/json.go

View check run for this annotation

Codecov / codecov/patch

util/codecs/json.go#L165

Added line #L165 was not covered by tests
if err == nil {
writer.Flush()
}
Expand Down

0 comments on commit 222173e

Please sign in to comment.