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) }