func PrintUsageOnRequiredFlagErrorHandlerDecorator(fn func(*cobra.Command, error)) func(*cobra.Command, error) {
	return func(command *cobra.Command, err error) {
		fn(command, err)
		if !isRequiredFlagError(err) {
			return
		}
		command.Println(strings.TrimSuffix(command.UsageString(), "\n"))
	}
}
PrintUsageOnRequiredFlagErrorHandlerDecorator decorates the provided error handler to add functionality that prints
the command usage if the error that occurred was due to a required flag not being specified. This handler first
processes the error using the provided handler. Then, it examines the string returned by the Error() function of the
error to determine if it matches the form of an error that indicates that a required flag was missing. If so, the
usage string of the command is printed.
package cobracli
import (
	"fmt"
	"io/ioutil"
	"strings"
	"github.com/spf13/cobra"
)
func Execute(rootCmd *cobra.Command, params ...Param) int {
	executor := &executor{}
	for _, p := range params {
		if p == nil {
			continue
		}
		p.apply(executor)
	}
	for _, configureCmd := range executor.rootCmdConfigurers {
		configureCmd(rootCmd)
	}
	executedCmd, err := rootCmd.ExecuteC()
	if err == nil {
		return 0
	}
	if executor.errorHandler != nil {
		executor.errorHandler(executedCmd, err)
	}
	if executor.exitCodeExtractor != nil {
		return executor.exitCodeExtractor(err)
	}
	return 1
}
type executor struct {
	rootCmdConfigurers []func(*cobra.Command)
	errorHandler       func(*cobra.Command, error)
	exitCodeExtractor  func(error) int
}
type Param interface {
	apply(*executor)
}
type paramFunc func(*executor)
func (f paramFunc) apply(e *executor) {
	f(e)
}
func ExitCodeExtractorParam(extractor func(error) int) Param {
	return paramFunc(func(executor *executor) {
		executor.exitCodeExtractor = extractor
	})
}
func ErrorHandlerParam(handler func(*cobra.Command, error)) Param {
	return paramFunc(func(executor *executor) {
		executor.errorHandler = handler
	})
}
func ErrorPrinterWithDebugHandler(debugVar *bool, debugErrTransform func(error) string) func(*cobra.Command, error) {
	return func(command *cobra.Command, err error) {
		errStr := err.Error()
		if errStr == "" {
			return
		}
		if debugVar != nil && *debugVar && debugErrTransform != nil {
			errStr = debugErrTransform(err)
		}
		command.Println("Error:", errStr)
	}
}