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

fix: cosign flags been ignored #2353

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Changes from all commits
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
20 changes: 20 additions & 0 deletions cmd/cosign/cli/options/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package options

import (
"fmt"
"os"
"strings"
"time"

Expand Down Expand Up @@ -53,12 +54,31 @@ func (o *RootOptions) AddFlags(cmd *cobra.Command) {
}

func BindViper(cmd *cobra.Command, args []string) {
callPersistentPreRun(cmd, args)
v := viper.New()
v.SetEnvPrefix(EnvPrefix)
v.AutomaticEnv()
bindFlags(cmd, v)
}

// callPersistentPreRun calls parent commands. PersistentPreRun
// does not call parents PersistentPreRun functions
func callPersistentPreRun(cmd *cobra.Command, args []string) {
if parent := cmd.Parent(); parent != nil {
if parent.PersistentPreRun != nil {
parent.PersistentPreRun(parent, args)
}
if parent.PersistentPreRunE != nil {
err := parent.PersistentPreRunE(parent, args)
if err != nil {
cmd.PrintErrln("Error:", err.Error())
os.Exit(1)
}
}
callPersistentPreRun(parent, args)
}
}

func bindFlags(cmd *cobra.Command, v *viper.Viper) {
cmd.Flags().VisitAll(func(f *pflag.Flag) {
if strings.Contains(f.Name, "-") {
Expand Down