-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdatecmd.go
57 lines (47 loc) · 1.03 KB
/
updatecmd.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
52
53
54
55
56
57
package main
import (
"context"
"flag"
"fmt"
"io/ioutil"
"regexp"
"github.com/google/subcommands"
"github.com/malice-plugins/go-plugin-utils/utils"
)
var versionExp = regexp.MustCompile(`(?m)(\d+\.\d+\.\d+)`)
type updateCmd struct {
c subcommands.Command
}
func (p *updateCmd) Name() string {
return "update"
}
func (p *updateCmd) Synopsis() string {
return "update"
}
func (p *updateCmd) Usage() string {
return "update"
}
func (p *updateCmd) SetFlags(*flag.FlagSet) {
}
func (p *updateCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
{
ctx := context.TODO()
r, err := utils.RunCommand(ctx, "hmb", "update")
fmt.Println(r)
if err != nil {
return subcommands.ExitFailure
}
//TODO:: parse is updated
}
{
ctx := context.TODO()
r, err := utils.RunCommand(ctx, "hmb", "version")
if err == nil {
v := versionExp.FindAllStringSubmatch(r, 1)
if len(v) > 0 {
ioutil.WriteFile("/opt/hmb/VERSION", []byte(v[0][1]), 0644)
}
}
}
return subcommands.ExitSuccess
}