-
Notifications
You must be signed in to change notification settings - Fork 4
/
upgrade.go
50 lines (41 loc) · 984 Bytes
/
upgrade.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package upgrade
import (
"github.com/maogou/pep-ebook/internal/command"
"github.com/rs/xid"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"github.com/urfave/cli/v2"
)
type Upgrade struct {
command.DebugLog
enableLog bool
ZLog zerolog.Logger
}
func newUpgrade() *Upgrade {
return &Upgrade{
enableLog: viper.GetBool("debug"),
ZLog: log.Logger.With().Str("qid", xid.New().String()).Logger(),
}
}
func (u *Upgrade) EnableDebug() bool {
return u.enableLog
}
func (u *Upgrade) PrintLog(key string, value ...any) {
if u.EnableDebug() {
u.ZLog.Info().Any(key, value).Send()
}
}
var _ command.DebugLog = (*Upgrade)(nil)
func UpgradeCommand() *cli.Command {
cmd := &cli.Command{
Name: "upgrade",
Usage: "升级pep-ebook到最新版本",
Description: "使用示例: ebook upgrade",
Action: func(cCtx *cli.Context) error {
upgrade := newUpgrade()
return upgrade.Execute(cCtx)
},
}
return cmd
}