Debian Codegraph @

otelcol/command_validate.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package otelcol // import "go.opentelemetry.io/collector/otelcol"
5
6 import (
7 "flag"
8
9 "github.com/spf13/cobra"
10 )
11
12 // newValidateSubCommand constructs a new validate sub command using the given CollectorSettings.
13 func newValidateSubCommand(set CollectorSettings, flagSet *flag.FlagSet) *cobra.Command {
14 validateCmd := &cobra.Command{
15 Use: "validate",
16 Short: "Validates the config without running the collector",
17 Args: cobra.ExactArgs(0),
18 RunE: func(cmd *cobra.Command, _ []string) error {
19 if err := updateSettingsUsingFlags(&set, flagSet); err != nil {
20 return err
21 }
22 col, err := NewCollector(set)
23 if err != nil {
24 return err
25 }
26 return col.DryRun(cmd.Context())
27 },
28 }
29 validateCmd.Flags().AddGoFlagSet(flagSet)
30 return validateCmd
31 }