Skip to content

Commit

Permalink
Resolves Issue jaegertracing#5168: Adding the print-config subcommand
Browse files Browse the repository at this point in the history
Signed-off-by: Guilherme Mafra da Costa <g.mafra.costa@gmail.com>
  • Loading branch information
gmafrac committed Feb 11, 2024
1 parent 951943f commit 9f7e1d4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/all-in-one/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/jaegertracing/jaeger/cmd/all-in-one/setupcontext"
collectorApp "github.com/jaegertracing/jaeger/cmd/collector/app"
collectorFlags "github.com/jaegertracing/jaeger/cmd/collector/app/flags"
print_config "github.com/jaegertracing/jaeger/cmd/internal/config"
"github.com/jaegertracing/jaeger/cmd/internal/docs"
"github.com/jaegertracing/jaeger/cmd/internal/env"
"github.com/jaegertracing/jaeger/cmd/internal/flags"
Expand Down Expand Up @@ -229,6 +230,7 @@ by default uses only in-memory database.`,
command.AddCommand(env.Command())
command.AddCommand(docs.Command(v))
command.AddCommand(status.Command(v, ports.CollectorAdminHTTP))
command.AddCommand(print_config.Command(v))

config.AddFlags(
v,
Expand Down
2 changes: 2 additions & 0 deletions cmd/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/jaegertracing/jaeger/cmd/collector/app"
"github.com/jaegertracing/jaeger/cmd/collector/app/flags"
printConfig "github.com/jaegertracing/jaeger/cmd/internal/config"
"github.com/jaegertracing/jaeger/cmd/internal/docs"
"github.com/jaegertracing/jaeger/cmd/internal/env"
cmdFlags "github.com/jaegertracing/jaeger/cmd/internal/flags"
Expand Down Expand Up @@ -142,6 +143,7 @@ func main() {
command.AddCommand(env.Command())
command.AddCommand(docs.Command(v))
command.AddCommand(status.Command(v, ports.CollectorAdminHTTP))
command.AddCommand(printConfig.Command(v))

config.AddFlags(
v,
Expand Down
41 changes: 41 additions & 0 deletions cmd/internal/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2018 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package print_config

import (
"fmt"
"sort"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func Command(v *viper.Viper) *cobra.Command {
c := &cobra.Command{
Use: "print-config",
Short: "Print configurations",
Long: `Iterates through the environment variables and prints them out`,
RunE: func(cmd *cobra.Command, args []string) error {
keys := v.AllKeys()
sort.Strings(keys)

for _, env := range keys {
value := v.Get(env)
fmt.Printf("%s=%v\n", env, value)
}
return nil
},
}
return c
}

0 comments on commit 9f7e1d4

Please sign in to comment.