-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
51 lines (43 loc) · 1.12 KB
/
main.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
51
package main
import (
"github.com/kldzj/pzmod/commands"
"github.com/kldzj/pzmod/interactive"
"github.com/kldzj/pzmod/util"
"github.com/kldzj/pzmod/version"
"github.com/spf13/cobra"
)
func main() {
var rootCmd = &cobra.Command{
Use: "pzmod --file <server config file>",
Short: "pzmod is a tool for managing Project Zomboid server mods.",
Version: version.Get(),
Example: `pzmod --file server.ini
pzmod --file server.ini get list
pzmod --file server.ini get name
pzmod --file server.ini set name "My Server"`,
PreRun: checkForUpdate,
Run: interactive.Execute,
}
commands.SetFileFlag(rootCmd)
commands.Init(rootCmd)
rootCmd.Execute()
}
func checkForUpdate(cmd *cobra.Command, args []string) {
if !version.IsSet() {
return
}
updater, err := version.NewUpdater()
if err != nil {
return
}
ver := version.Get()
latest, err := version.GetLatestRelease(updater)
if err != nil {
return
}
if version.IsLatest(ver, latest) {
return
}
cmd.Println(util.Info, "A new version of pzmod is available:", latest.Version())
cmd.Println(util.Info, "Run `pzmod update` to update to the latest version.")
}