Skip to content

Commit

Permalink
Remove unnecessary posflag provider load (#5951)
Browse files Browse the repository at this point in the history
This is unnecessary because:
1. It happens before flags are loaded, so will initialize things with default values, which already happens during flags initialization. See flags.StringVar for example.
2. The load using posflag provider, as defined right now (with current flags name) produce this config:
```
k := map[string]interface{} {
	"config": ""
	"description": "Custom OpenTelemetry Collector distribution"
	"go": ""
	"module": "go.opentelemetry.io/collector/cmd/builder"
	"name": "otelcol-custom otelcol-version:0.58.0"
	"output-path": "/var/folders/5c/5p_3jmvd6qx0rsvmb9j7c_s00000gn/T/otelcol-distribution1155391158"
	"skip-compilation": false
	"version": "1.0.0"
}
```
As you can see, this will whole be ignored, since all the configs (except the config flag) are sub-configs under "dist" anyway.
Signed-off-by: Bogdan <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Aug 25, 2022
1 parent e092fc7 commit 7545a29
Showing 1 changed file with 0 additions and 5 deletions.
5 changes: 0 additions & 5 deletions cmd/builder/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/knadh/koanf/parsers/yaml"
"github.com/knadh/koanf/providers/env"
"github.com/knadh/koanf/providers/file"
"github.com/knadh/koanf/providers/posflag"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"go.uber.org/zap"
Expand Down Expand Up @@ -118,10 +117,6 @@ build configuration given by the "--config" argument.
// version of this binary
cmd.AddCommand(versionCommand())

if err := k.Load(posflag.Provider(cmd.Flags(), ".", k), nil); err != nil {
return nil, fmt.Errorf("failed to load command line arguments: %w", err)
}

return cmd, nil
}

Expand Down

0 comments on commit 7545a29

Please sign in to comment.