Skip to content

Commit

Permalink
sync margo
Browse files Browse the repository at this point in the history
fixes #964
re: #916
  • Loading branch information
DisposaBoy committed Mar 9, 2020
1 parent e287a3b commit 08b738f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/margo.sh/.github/workflows/margo-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
margo-ci:
strategy:
matrix:
go-version: [1.12.x, 1.13.x]
go-version: [1.13.x, 1.14.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion src/margo.sh/extension-example/extension-example.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Margo(m mg.Args) {
m.Use(
// MOTD keeps you updated about new versions and important announcements
//
// It adds a new command `motd.sync` available via the UserCmd palette as `Sync MOTD`
// It adds a new command `motd.sync` available via the UserCmd palette as `Sync MOTD (check for updates)`
//
// Interval can be set in order to enable automatic update fetching.
//
Expand Down
27 changes: 24 additions & 3 deletions src/margo.sh/mg/motd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type motdState struct {

// MOTD keeps you updated about new versions and important announcements
//
// It adds a new command `motd.sync` available via the UserCmd palette as `Sync MOTD`
// It adds a new command `motd.sync` available via the UserCmd palette as `Sync MOTD (check for updates)`
//
// Interval can be set in order to enable automatic update fetching.
//
Expand Down Expand Up @@ -96,7 +96,7 @@ func (m *MOTD) Reduce(mx *Ctx) *State {
case RunCmd:
st = st.AddBuiltinCmds(BuiltinCmd{Name: "motd.sync", Run: m.motdSyncCmd})
case QueryUserCmds:
st = st.AddUserCmds(UserCmd{Title: "Sync MOTD", Name: "motd.sync"})
st = st.AddUserCmds(UserCmd{Title: "Sync MOTD (check for updates)", Name: "motd.sync"})
case motdAct:
m.msg = act.msg
}
Expand Down Expand Up @@ -179,14 +179,35 @@ func (m *MOTD) sync(mx *Ctx) error {
return nil
}

func (_ *MOTD) fmtTag(s string) (string, error) {
var y, m, d, n int
scanned, err := fmt.Sscanf(s, "%02d.%02d.%02d-%d", &y, &m, &d, &n)
if scanned < 4 {
_, err = fmt.Sscanf(s, "%02d.%02d.%02d", &y, &m, &d)
}
if err != nil {
return "", err
}
if n <= 0 {
n = 1
}
return fmt.Sprintf("%02d.%02d.%02d-%d", y, m, d, n), nil
}

func (m *MOTD) dispatchMsg(mx *Ctx, ms motdState) {
res := ms.Result
act := motdAct{}
ctag := mx.Editor.Client.Tag
srvTag, srvTagErr := m.fmtTag(res.Tag)
cliTag, cliTagErr := m.fmtTag(ctag)
switch {
case ctag == "":
mx.Log.Println("motd: client tag is undefined; you might need to restart the editor")
case res.Tag != ctag:
case srvTagErr != nil:
mx.Log.Println("motd: cannot parse ser`ver tag:", srvTagErr)
case cliTagErr != nil:
mx.Log.Println("motd: cannot parse client tag:", cliTagErr)
case cliTag < srvTag:
act.msg = res.Message
}
mx.Store.Dispatch(act)
Expand Down
2 changes: 2 additions & 0 deletions src/margo.sh/sublime/sublime.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func buildAction(c *cli.Context) error {
pkg, err := extensionPkg()
if modSet {
os.Setenv("GO111MODULE", modWas)
} else {
os.Unsetenv("GO111MODULE")
}
if err == nil {
fixExtPkg(pkg)
Expand Down

0 comments on commit 08b738f

Please sign in to comment.