Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd/builder] Update builder flags precedence #5726

Merged
merged 7 commits into from
Jul 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix const name and extract method
  • Loading branch information
TylerHelmuth committed Jul 21, 2022
commit f34584b43df46ad8afa134184311cd45ec07bd31
32 changes: 19 additions & 13 deletions cmd/builder/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ import (
"go.opentelemetry.io/collector/cmd/builder/internal/builder"
)

const SkipComplicationFlag = "skip-compilation"
const DistributionNameFlag = "name"
const DistributionDescriptionFlag = "description"
const DistributionVersionFlag = "version"
const DistributionOtelColVersionFlag = "otelcol-version"
const DistributionOutputPathFlag = "output-path"
const DistributionGoFlag = "go"
const DistributionModuleFlag = "module"
const (
SkipCompilationFlag = "skip-compilation"
DistributionNameFlag = "name"
DistributionDescriptionFlag = "description"
DistributionVersionFlag = "version"
DistributionOtelColVersionFlag = "otelcol-version"
DistributionOutputPathFlag = "output-path"
DistributionGoFlag = "go"
DistributionModuleFlag = "module"
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
)

var (
cfgFile string
Expand Down Expand Up @@ -72,7 +74,7 @@ func Command() (*cobra.Command, error) {
cmd.Flags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.otelcol-builder.yaml)")

// the distribution parameters, which we accept as CLI flags as well
cmd.Flags().BoolVar(&cfg.SkipCompilation, SkipComplicationFlag, false, "Whether builder should only generate go code with no compile of the collector (default false)")
cmd.Flags().BoolVar(&cfg.SkipCompilation, SkipCompilationFlag, false, "Whether builder should only generate go code with no compile of the collector (default false)")
cmd.Flags().StringVar(&cfg.Distribution.Name, DistributionNameFlag, "otelcol-custom", "The executable name for the OpenTelemetry Collector distribution")
cmd.Flags().StringVar(&cfg.Distribution.Description, DistributionDescriptionFlag, "Custom OpenTelemetry Collector distribution", "A descriptive name for the OpenTelemetry Collector distribution")
cmd.Flags().StringVar(&cfg.Distribution.Version, DistributionVersionFlag, "1.0.0", "The version for the OpenTelemetry Collector distribution")
Expand Down Expand Up @@ -116,14 +118,21 @@ func initConfig(flags *flag.FlagSet) error {
return err
}

applyCfgFromFile(flags, cfgFromFile)

cfg.Logger.Info("Using config file", zap.String("path", cfgFile))
return nil
}

func applyCfgFromFile(flags *flag.FlagSet, cfgFromFile builder.Config) {
cfg.Exporters = cfgFromFile.Exporters
cfg.Extensions = cfgFromFile.Extensions
cfg.Receivers = cfgFromFile.Receivers
cfg.Processors = cfgFromFile.Processors
cfg.Replaces = cfgFromFile.Replaces
cfg.Excludes = cfgFromFile.Excludes

if !flags.Changed(SkipComplicationFlag) && cfgFromFile.SkipCompilation {
if !flags.Changed(SkipCompilationFlag) && cfgFromFile.SkipCompilation {
cfg.SkipCompilation = cfgFromFile.SkipCompilation
}
if !flags.Changed(DistributionNameFlag) && cfgFromFile.Distribution.Name != "" {
Expand All @@ -147,7 +156,4 @@ func initConfig(flags *flag.FlagSet) error {
if !flags.Changed(DistributionModuleFlag) && cfgFromFile.Distribution.Module != "" {
cfg.Distribution.Module = cfgFromFile.Distribution.Module
}

cfg.Logger.Info("Using config file", zap.String("path", cfgFile))
return nil
}