Skip to content

Commit

Permalink
fix(cli): fix flag parsing
Browse files Browse the repository at this point in the history
In order to properly bind flags by Viper we need to expose the Go flags we
set to pflag.
  • Loading branch information
goldmann authored and tekton-robot committed Apr 1, 2022
1 parent 9d78ebe commit 280399e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 5 additions & 2 deletions tools/tkn-results/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package cmd

import (
_ "embed"
"flag"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/tektoncd/results/tools/tkn-results/cmd/records"
"github.com/tektoncd/results/tools/tkn-results/internal/client"
Expand Down Expand Up @@ -41,9 +43,10 @@ func Root() *cobra.Command {
cmd.PersistentFlags().StringP("addr", "a", "", "Result API server address")
cmd.PersistentFlags().StringP("authtoken", "t", "", "authorization bearer token to use for authenticated requests")

viper.BindPFlags(cmd.PersistentFlags())

cmd.AddCommand(ListCommand(params), records.Command(params))

pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
viper.BindPFlags(cmd.PersistentFlags())

return cmd
}
1 change: 0 additions & 1 deletion tools/tkn-results/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func init() {
}

func GetConfig() (*Config, error) {
pflag.Parse()
if err := viper.BindPFlags(pflag.CommandLine); err != nil {
return nil, err
}
Expand Down

0 comments on commit 280399e

Please sign in to comment.