Skip to content

Commit

Permalink
fix: removes dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszmajsak committed Apr 15, 2020
1 parent 23f8e5b commit 86bec42
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 62 deletions.
17 changes: 0 additions & 17 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 0 additions & 45 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import (
"path"
"strings"

"github.com/hashicorp/go-multierror"

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

Expand Down Expand Up @@ -67,44 +63,3 @@ func contains(s []string, e string) bool {
}
return false
}

// SyncFlag ensures that if configuration provides a value for a given cmd.flag it will be set back to the flag itself,
// but only if the flag was not set through CLI.
//
// This way we can make flags required but still have their values provided by the configuration source
func SyncFlag(cmd *cobra.Command, flagName string) error { //nolint[:unused]
value := viper.GetString(cmd.Name() + "." + flagName)
if value != "" && !cmd.Flag(flagName).Changed {
return cmd.Flags().Set(flagName, value)
}
return nil
}

// SyncFlags ensures that if configuration provide a value for any of defined flags it will be set
// back to the flag itself.
//
// This function iterates over all flags defined for cobra.Command and accumulates errors if they occur while
// calling SyncFlag for every flag.
func SyncFlags(cmd *cobra.Command) error { //nolint[:unused]
var accErrors *multierror.Error
cmd.Flags().VisitAll(func(flag *pflag.Flag) {
syncFlagErr := SyncFlag(cmd, flag.Name)
accErrors = multierror.Append(accErrors, syncFlagErr)
})
return accErrors.ErrorOrNil()
}

// BindFullyQualifiedFlag ensures that each flag used in commands is bound to a key using fully qualified name
// which has a following form:
//
// commandName.flagName
//
// This lets us keep structure of yaml file:
//
// commandName:
// flagName: value
func BindFullyQualifiedFlag(cmd *cobra.Command) func(flag *pflag.Flag) { //nolint[:unused]
return func(flag *pflag.Flag) {
_ = viper.BindPFlag(cmd.Name()+"."+flag.Name, flag)
}
}

0 comments on commit 86bec42

Please sign in to comment.