Files
telemetry/otelcol/command_validate.go
Tyler HelmuthandGitHub 0f7e07e364 [otelcol] Remove all default providers/converters (#10436)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Removed deprecated `NewCommand`. Deprecates `NewCommandMustSetProvider`.
Adds `NewCommand` that requires at least one provider be set.

Removes usage of imported providers/converters from otelcol (but they
still live in otelcoltest until
https://github.com/open-telemetry/opentelemetry-collector/pull/10417 is
merged.

<!-- Issue number if applicable -->
#### Link to tracking issue
closes
https://github.com/open-telemetry/opentelemetry-collector/issues/10290.

<!--Describe what testing was performed and which tests were added.-->
#### Testing
Unit tests
2024-06-28 10:33:11 +02:00

32 lines
847 B
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package otelcol // import "go.opentelemetry.io/collector/otelcol"
import (
"flag"
"github.com/spf13/cobra"
)
// newValidateSubCommand constructs a new validate sub command using the given CollectorSettings.
func newValidateSubCommand(set CollectorSettings, flagSet *flag.FlagSet) *cobra.Command {
validateCmd := &cobra.Command{
Use: "validate",
Short: "Validates the config without running the collector",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, _ []string) error {
if err := updateSettingsUsingFlags(&set, flagSet); err != nil {
return err
}
col, err := NewCollector(set)
if err != nil {
return err
}
return col.DryRun(cmd.Context())
},
}
validateCmd.Flags().AddGoFlagSet(flagSet)
return validateCmd
}