wal-g

Форк
0
/
pg.go 
62 строки · 1.7 Кб
1
package pg
2

3
import (
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"
13
	conf "github.com/wal-g/wal-g/internal/config"
14
	"github.com/wal-g/wal-g/internal/databases/postgres"
15
)
16

17
const WalgShortDescription = "PostgreSQL backup tool"
18

19
var (
20
	// These variables are here only to show current version. They are set in makefile during build process
21
	walgVersion = "devel"
22
	gitRevision = "devel"
23
	buildDate   = "devel"
24

25
	Cmd = &cobra.Command{
26
		Use:     "wal-g",
27
		Short:   WalgShortDescription, // TODO : improve short and long descriptions
28
		Version: strings.Join([]string{walgVersion, gitRevision, buildDate, "PostgreSQL"}, "\t"),
29
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
30
			err := internal.AssertRequiredSettingsSet()
31
			tracelog.ErrorLogger.FatalOnError(err)
32

33
			if viper.IsSet(conf.PgWalSize) {
34
				postgres.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.
39
			if targetStorage == "" {
40
				targetStorage = viper.GetString(conf.PgTargetStorage)
41
			}
42
		},
43
	}
44

45
	targetStorage            string
46
	targetStorageDescription = `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.
51
func Execute() {
52
	configureCommand()
53
	if err := Cmd.Execute(); err != nil {
54
		fmt.Println(err)
55
		os.Exit(1)
56
	}
57
}
58

59
func configureCommand() {
60
	common.Init(Cmd, conf.PG)
61
	conf.AddTurboFlag(Cmd)
62
}
63

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.