wal-g
1package pg2
3import (4"fmt"5"os"6"strings"7
8"github.com/spf13/cobra"9"github.com/spf13/viper"10"github.com/wal-g/tracelog"11"github.com/wal-g/wal-g/cmd/common"12"github.com/wal-g/wal-g/internal"13conf "github.com/wal-g/wal-g/internal/config"14"github.com/wal-g/wal-g/internal/databases/postgres"15)
16
17const WalgShortDescription = "PostgreSQL backup tool"18
19var (20// These variables are here only to show current version. They are set in makefile during build process21walgVersion = "devel"22gitRevision = "devel"23buildDate = "devel"24
25Cmd = &cobra.Command{26Use: "wal-g",27Short: WalgShortDescription, // TODO : improve short and long descriptions28Version: strings.Join([]string{walgVersion, gitRevision, buildDate, "PostgreSQL"}, "\t"),29PersistentPreRun: func(cmd *cobra.Command, args []string) {30err := internal.AssertRequiredSettingsSet()31tracelog.ErrorLogger.FatalOnError(err)32
33if viper.IsSet(conf.PgWalSize) {34postgres.SetWalSize(viper.GetUint64(conf.PgWalSize))35}36
37// In case the --target-storage flag isn't specified (the variable is set in commands' init() funcs),38// we take the value from the config.39if targetStorage == "" {40targetStorage = viper.GetString(conf.PgTargetStorage)41}42},43}44
45targetStorage string46targetStorageDescription = `Name of the storage to execute the command only for. Use "default" to select the primary one.`47)
48
49// Execute adds all child commands to the root command and sets flags appropriately.
50// This is called by main.main(). It only needs to happen once to the PgCmd.
51func Execute() {52configureCommand()53if err := Cmd.Execute(); err != nil {54fmt.Println(err)55os.Exit(1)56}57}
58
59func configureCommand() {60common.Init(Cmd, conf.PG)61conf.AddTurboFlag(Cmd)62}
63