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
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-adm/internal/modules/config"
|
2021-07-09 09:53:10 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-adm/internal/modules/morph"
|
2022-01-26 11:27:06 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-adm/internal/modules/storagecfg"
|
2021-07-06 11:27:54 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/misc"
|
2022-01-11 12:24:06 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/autocomplete"
|
2022-05-18 15:21:54 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/gendoc"
|
2021-07-06 11:27:54 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
rootCmd = &cobra.Command{
|
|
|
|
Use: "neofs-adm",
|
|
|
|
Short: "NeoFS Administrative Tool",
|
|
|
|
Long: `NeoFS Administrative Tool provides functions to setup and
|
|
|
|
manage NeoFS network deployment.`,
|
|
|
|
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)
|
|
|
|
|
2021-07-06 11:27:54 +00:00
|
|
|
rootCmd.PersistentFlags().StringP(configFlag, "c", "", "config file")
|
|
|
|
rootCmd.Flags().Bool("version", false, "application version")
|
|
|
|
|
|
|
|
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-01-11 12:24:06 +00:00
|
|
|
rootCmd.AddCommand(autocomplete.Command("neofs-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 {
|
|
|
|
printVersion, err := cmd.Flags().GetBool("version")
|
|
|
|
if err == nil && printVersion {
|
2022-07-08 12:45:21 +00:00
|
|
|
cmd.Print(misc.BuildInfo("NeoFS 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
|
|
|
|
}
|