Skip to content
This repository was archived by the owner on Dec 17, 2021. It is now read-only.

Commit b20cafa

Browse files
committed
commands/updatecli: Add
1 parent e14a7e6 commit b20cafa

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

commands/updatecli.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package commands
2+
3+
import (
4+
"github.com/blang/semver"
5+
"github.com/docker/machine/libmachine"
6+
"github.com/docker/machine/libmachine/log"
7+
"github.com/lambda-linux/lambda-machine-local/version"
8+
"github.com/rhysd/go-github-selfupdate/selfupdate"
9+
)
10+
11+
const (
12+
slug = "lambda-linux/lambda-machine-local"
13+
)
14+
15+
func cmdUpdateCli(c CommandLine, api libmachine.API) error {
16+
if len(c.Args()) != 0 {
17+
return ErrTooManyArguments
18+
}
19+
20+
if log.GetDebug() {
21+
log.Debug("Enabling selfupdate.EnableLog()")
22+
selfupdate.EnableLog()
23+
}
24+
25+
latest_gh, found, err := selfupdate.DetectLatest(slug)
26+
if err != nil {
27+
log.Info(err)
28+
return nil
29+
}
30+
if !found {
31+
log.Info("No release was found")
32+
return nil
33+
}
34+
35+
current_ver := semver.MustParse(version.Version)
36+
37+
if current_ver.GTE(latest_gh.Version) {
38+
log.Infof("Lambda Machine Local version %s is currently the latest version", current_ver)
39+
return nil
40+
}
41+
42+
log.Info("Starting update...")
43+
latest_gh, err = selfupdate.UpdateSelf(current_ver, slug)
44+
if err != nil {
45+
log.Info(err)
46+
return nil
47+
}
48+
log.Infof("Updated to latest Lambda Machine Local version %s", latest_gh.Version)
49+
50+
return nil
51+
}

0 commit comments

Comments
 (0)