func InitClientConfigFile(flags *pflag.FlagSet) {
	flags.StringVar(&opts.clientConfigFile, clientConfigFileFlag, defaultClientConfigFile, clientConfigFileDescription)
}
InitClientConfigFile initializes the config file path from the provided arguments
package cliconfig
import (
	"fmt"
	"strconv"
	"strings"
	"time"
	fabApi "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
	mspApi "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
	"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
	"github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite/bccsp/multisuite"
	"github.com/hyperledger/fabric-sdk-go/pkg/fab"
	"github.com/hyperledger/fabric-sdk-go/pkg/msp"
	"github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
	"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
	"github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite"
	"github.com/securekey/fabric-snaps/util/errors"
	"github.com/spf13/pflag"
)
const (
	ConfigSnapID = "configurationsnap"
	loggerName = "configcli"
)
const (
	loggingLevelFlag        = "logging-level"
	loggingLevelDescription = "Logging level - ERROR, WARN, INFO, DEBUG"
	defaultLoggingLevel     = "ERROR"
	clientConfigFileFlag        = "clientconfig"
	clientConfigFileDescription = "The path of the client SDK's config.yaml file"
	defaultClientConfigFile     = ""
	userFlag        = "user"
	userDescription = "The user used to connect to Fabric"
	defaultUser     = ""
	passwordFlag        = "pw"
	passwordDescription = "The password of the user"
	defaultPassword     = ""
	channelIDFlag        = "cid"
	channelIDDescription = "The channel ID"
	defaultChannelID     = ""
	orgIDFlag        = "orgid"
	orgIDDescription = "A comma-separated set of peers, e.g. org1,org2. If specified then the request is made to all peers for the given organization"
	defaultOrgID     = ""
	peerURLFlag        = "peerurl"
	peerURLDescription = "A comma-separated list of target peers to query/update, e.g. 'grpcs://localhost:7051,grpcs://localhost:8051'"
	defaultPeerURL     = ""
	configKeyFlag        = "configkey"
	configKeyDescription = "The config key in JSON format. Example: {\"MspID\":\"Org1MSP\",\"PeerID\":\"peer0.org1.example.com\",\"AppName\":\"app1\",\"Version\":\"1\"}"
	configFlag        = "config"
	configDescription = "The config update string in JSON format. Example: {\"MspID\":\"Org1MSP\",\"Peers\":[{\"PeerID\":\"peer0.org1.example.com\",\"App\":[{\"AppName\":\"myapp\",\"Version\":\"1\",\"Config\":\"some config\"}]}]}"
	configFileFlag        = "configfile"
	configFileDescription = "The path to the config file"
	timeoutFlag        = "timeout"
	timeoutDescription = "The timeout (in milliseconds) for the operation"
	defaultTimeout     = "3000"
	outputFormatFlag        = "format"
	outputFormatDescription = "The output format - display, raw"
	defaultOutputFormat     = "formatted"
	mspIDFlag        = "mspid"
	mspIDDescription = "The ID of the MSP"
	defaultMSPID     = ""
	peerIDFlag        = "peerid"
	peerIDDescription = "The ID of the peer to query for"
	appNameFlag        = "appname"
	appNameDescription = "The name of the application to query for"
	appVerFlag        = "appver"
	appVerDescription = "The app version"
	componentNameFlag        = "componentname"
	componentNameDescription = "The name of the component to query for"
	componentVerFlag        = "componentver"
	componentVerDescription = "The component version"
	noPromptFlag        = "noprompt"
	noPromptDescription = "If specified then update and delete operations will not prompt for confirmation"
	defaultNoPrompt     = false
	keyType            = "keyType"
	keyTypeDescription = "Key type to be used to generate CSR"
	ephemeral            = "ephemeral"
	ephemeralDescription = "To be used in generate CSR - default false - long lived keys"
	ephemeralDefault     = "false"
	sigAlg            = "sigAlg"
	sigAlgDescription = "Signature Algorithm used to generate CSR"
	csrCommonName     = "csrCommonName"
	csrCommonNameDesc = "CSR common name"
)
var opts *options
var instance *CLIConfig
type options struct {
	user             string
	password         string
	loggingLevel     string
	orgID            string
	channelID        string
	peerURL          string
	clientConfigFile string
	configFile       string
	configKey        string
	config           string
	timeout          int64
	outputFormat     string
	mspID            string
	peerID           string
	appName          string
	appVer           string
	componentName    string
	componentVer     string
	noPrompt         bool
	keyType          string
	ephemeralFlag    string
	sigAlg           string
	csrCommonName    string
}
func init() {
	opts = &options{
		user:         defaultUser,
		password:     defaultPassword,
		loggingLevel: defaultLoggingLevel,
		channelID:    defaultChannelID,
	}
}
type CLIConfig struct {
	fabApi.EndpointConfig
	mspApi.IdentityConfig
	core.CryptoSuiteConfig
	logger *logging.Logger
}
func InitConfig() error {
	instance = &CLIConfig{
		logger: logging.NewLogger(loggerName),
	}
	if opts.clientConfigFile == "" {
		return errors.New(errors.GeneralError, "no client config file specified")
	}
	provider := config.FromFile(opts.clientConfigFile)
	cnfg, err := provider()
	if err != nil {
		return errors.WithMessage(errors.GeneralError, err, "error loading the configs")
	}
	cryptoConfig := cryptosuite.ConfigFromBackend(cnfg...)
	cryptoSuiteProvider, err := multisuite.GetSuiteByConfig(cryptoConfig)
	if err != nil {
		instance.logger.Warnf("Failed to get cryptosuite from config, will switch to default cryptosuite, %s", err)
	} else {
		err = cryptosuite.SetDefault(cryptoSuiteProvider)
		if err != nil {
			instance.logger.Warnf("Error setting default cryptosuite, %s", err)
		}
	}
	endpointConfig, err := fab.ConfigFromBackend(cnfg...)
	if err != nil {
		return errors.WithMessage(errors.GeneralError, err, "from backend returned error")
	}
	identityConfig, err := msp.ConfigFromBackend(cnfg...)
	if err != nil {
		return errors.WithMessage(errors.GeneralError, err, "from backend returned error")
	}
	instance.EndpointConfig = endpointConfig
	instance.IdentityConfig = identityConfig
	instance.CryptoSuiteConfig = cryptoConfig
	return nil
}
func Config() *CLIConfig {
	return instance
}
func (c *CLIConfig) Logger() *logging.Logger {
	return c.logger
}
func (c *CLIConfig) LoggingLevel() string {
	return opts.loggingLevel
}
func InitLoggingLevel(flags *pflag.FlagSet) {
	flags.StringVar(&opts.loggingLevel, loggingLevelFlag, defaultLoggingLevel, loggingLevelDescription)
}
func (c *CLIConfig) ClientConfigFile() string {
	return opts.clientConfigFile
}