2021-07-06 11:27:54 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
2022-04-12 08:23:14 +00:00
|
|
|
"os"
|
2021-07-06 11:27:54 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/config"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/storagecfg"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/misc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/autocomplete"
|
|
|
|
utilConfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/config"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/gendoc"
|
2021-07-06 11:27:54 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
rootCmd = &cobra.Command{
|
2022-12-23 17:35:35 +00:00
|
|
|
Use: "frostfs-adm",
|
2023-01-27 10:47:14 +00:00
|
|
|
Short: "FrostFS Administrative Tool",
|
|
|
|
Long: `FrostFS Administrative Tool provides functions to setup and
|
|
|
|
manage FrostFS network deployment.`,
|
2021-07-06 11:27:54 +00:00
|
|
|
RunE: entryPoint,
|
|
|
|
SilenceUsage: true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cobra.OnInitialize(func() { initConfig(rootCmd) })
|
|
|
|
// we need to init viper config to bind viper and cobra configurations for
|
|
|
|
// rpc endpoint, alphabet wallet dir, key credentials, etc.
|
|
|
|
|
2022-04-12 08:23:14 +00:00
|
|
|
// use stdout as default output for cmd.Print()
|
|
|
|
rootCmd.SetOut(os.Stdout)
|
|
|
|
|
2023-01-31 10:22:37 +00:00
|
|
|
rootCmd.PersistentFlags().StringP(commonflags.ConfigFlag, commonflags.ConfigFlagShorthand, "", commonflags.ConfigFlagUsage)
|
2023-02-06 14:54:49 +00:00
|
|
|
rootCmd.PersistentFlags().String(commonflags.ConfigDirFlag, "", commonflags.ConfigDirFlagUsage)
|
2023-01-31 10:33:33 +00:00
|
|
|
rootCmd.PersistentFlags().BoolP(commonflags.Verbose, commonflags.VerboseShorthand, false, commonflags.VerboseUsage)
|
|
|
|
_ = viper.BindPFlag(commonflags.Verbose, rootCmd.PersistentFlags().Lookup(commonflags.Verbose))
|
2022-10-11 14:02:03 +00:00
|
|
|
rootCmd.Flags().Bool("version", false, "Application version")
|
2021-07-06 11:27:54 +00:00
|
|
|
|
|
|
|
rootCmd.AddCommand(config.RootCmd)
|
2021-07-09 09:53:10 +00:00
|
|
|
rootCmd.AddCommand(morph.RootCmd)
|
2022-01-26 11:27:06 +00:00
|
|
|
rootCmd.AddCommand(storagecfg.RootCmd)
|
2021-12-14 11:04:23 +00:00
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
rootCmd.AddCommand(autocomplete.Command("frostfs-adm"))
|
2022-05-18 15:21:54 +00:00
|
|
|
rootCmd.AddCommand(gendoc.Command(rootCmd))
|
2021-07-06 11:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Execute() error {
|
|
|
|
return rootCmd.Execute()
|
|
|
|
}
|
|
|
|
|
2023-04-26 08:24:40 +00:00
|
|
|
func entryPoint(cmd *cobra.Command, _ []string) error {
|
2022-07-13 07:33:07 +00:00
|
|
|
printVersion, _ := cmd.Flags().GetBool("version")
|
|
|
|
if printVersion {
|
2023-01-27 10:41:03 +00:00
|
|
|
cmd.Print(misc.BuildInfo("FrostFS Adm"))
|
2021-07-06 11:27:54 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd.Usage()
|
|
|
|
}
|
|
|
|
|
|
|
|
func initConfig(cmd *cobra.Command) {
|
2023-01-31 10:22:37 +00:00
|
|
|
configFile, err := cmd.Flags().GetString(commonflags.ConfigFlag)
|
2023-02-06 14:54:49 +00:00
|
|
|
if err != nil {
|
2021-07-06 11:27:54 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-06 14:54:49 +00:00
|
|
|
if configFile != "" {
|
|
|
|
viper.SetConfigType("yml")
|
|
|
|
viper.SetConfigFile(configFile)
|
|
|
|
_ = viper.ReadInConfig() // if config file is set but unavailable, ignore it
|
|
|
|
}
|
|
|
|
|
|
|
|
configDir, err := cmd.Flags().GetString(commonflags.ConfigDirFlag)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if configDir != "" {
|
|
|
|
_ = utilConfig.ReadConfigDir(viper.GetViper(), configDir) // if config files cannot be read, ignore it
|
|
|
|
}
|
2021-07-06 11:27:54 +00:00
|
|
|
}
|