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
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/config"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/storagecfg"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/misc"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/autocomplete"
|
|
|
|
"github.com/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,
|
|
|
|
}
|
|
|
|
|
|
|
|
configFlag = "config"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-10-11 14:02:03 +00:00
|
|
|
rootCmd.PersistentFlags().StringP(configFlag, "c", "", "Config file")
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
|
|
|
func entryPoint(cmd *cobra.Command, args []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) {
|
|
|
|
configFile, err := cmd.Flags().GetString(configFlag)
|
|
|
|
if err != nil || configFile == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
viper.SetConfigType("yml")
|
|
|
|
viper.SetConfigFile(configFile)
|
|
|
|
_ = viper.ReadInConfig() // if config file is set but unavailable, ignore it
|
|
|
|
}
|