policy-reader/modules/root.go
Denis Kirillov ee7a08ef1f Support contract method invocation
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
2024-08-28 14:57:04 +03:00

52 lines
1.4 KiB
Go

package modules
import (
"context"
"runtime"
"strings"
"git.frostfs.info/dkirillov/policy-reader/internal/version"
"git.frostfs.info/dkirillov/policy-reader/modules/contract"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{
Use: "policy-reader",
Version: version.Version,
Short: "FrostFS policy contract reader",
Long: "Helps reading policy information from contact in FrostFS network",
Example: "policy-reader --version",
SilenceErrors: true,
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
viper.AutomaticEnv()
viper.SetEnvPrefix("POLICY_READER}")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AllowEmptyEnv(true)
return viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, _ []string) error {
return cmd.Help()
},
}
func Execute(ctx context.Context) (*cobra.Command, error) {
return rootCmd.ExecuteContextC(ctx)
}
const configFlag = "config"
func init() {
rootCmd.PersistentFlags().StringP(configFlag, "c", "", "Path to config file")
cobra.AddTemplateFunc("runtimeVersion", runtime.Version)
rootCmd.SetVersionTemplate(`Frostfs policy reader
{{printf "Version: %s" .Version }}
GoVersion: {{ runtimeVersion }}
`)
rootCmd.AddCommand(contract.Cmd)
}