0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-30 22:34:13 -05:00
zot/pkg/exporter/cli/cli.go
Alex Stan ada21ed842 Manage builds with different combinations of extensions
Files were added to be built whether an extension is on or off.
New build tags were added for each extension, while minimal and extended disappeared.

added custom binary naming depending on extensions used and changed references from binary to binary-extended

added automated blackbox tests for sync, search, scrub, metrics

added contributor guidelines

Signed-off-by: Alex Stan <alexandrustan96@yahoo.ro>
2022-06-30 09:53:52 -07:00

76 lines
1.7 KiB
Go

//go:build !metrics
// +build !metrics
package cli
import (
"github.com/mitchellh/mapstructure"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"zotregistry.io/zot/errors"
"zotregistry.io/zot/pkg/exporter/api"
)
// metadataConfig reports metadata after parsing, which we use to track
// errors.
func metadataConfig(md *mapstructure.Metadata) viper.DecoderConfigOption {
return func(c *mapstructure.DecoderConfig) {
c.Metadata = md
}
}
func NewExporterCmd() *cobra.Command {
config := api.DefaultConfig()
// "config"
configCmd := &cobra.Command{
Use: "config <config_file>",
Aliases: []string{"config"},
Short: "`config` node exporter properties",
Long: "`config` node exporter properties",
Run: func(cmd *cobra.Command, args []string) {
if len(args) > 0 {
loadConfiguration(config, args[0])
}
c := api.NewController(config)
c.Run()
},
}
// "node_exporter"
exporterCmd := &cobra.Command{
Use: "zxp",
Short: "`zxp`",
Long: "`zxp`",
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Usage()
cmd.SilenceErrors = false
},
}
exporterCmd.AddCommand(configCmd)
return exporterCmd
}
func loadConfiguration(config *api.Config, configPath string) {
viper.SetConfigFile(configPath)
if err := viper.ReadInConfig(); err != nil {
log.Error().Err(err).Msg("Error while reading configuration")
panic(err)
}
metaData := &mapstructure.Metadata{}
if err := viper.Unmarshal(&config, metadataConfig(metaData)); err != nil {
log.Error().Err(err).Msg("Error while unmarshalling new config")
panic(err)
}
if len(metaData.Keys) == 0 || len(metaData.Unused) > 0 {
log.Error().Err(errors.ErrBadConfig).Msg("Bad configuration, retry writing it")
panic(errors.ErrBadConfig)
}
}