Skip to content

Commit 3079b22

Browse files
authored
Merge pull request #22 from nao1215/notify
Added desktop notification
2 parents 0410763 + 26b7146 commit 3079b22

File tree

16 files changed

+133
-3
lines changed

16 files changed

+133
-3
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
33

4+
# [0.9.0] - 2022-03-18
5+
## Added
6+
- Added desktop notification: gup command will notify you on your desktop whether the update was successful or unsuccessful after the update was finished.
47
# [0.8.0] - 2022-03-18
58
## Added
69
- Added check subcommand: get the latest version of the binary installed by 'go install'"

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
![GitHub](https://img.shields.io/github/license/nao1215/gup)
66
[[日本語](./doc/ja/README.md)]
77
# gup - Update binaries installed by "go install"
8-
**gup** command update binaries installed by "go install" to the latest version. It also provides subcommands for manipulating binaries under \$GOPATH/bin (\$GOBIN).
8+
**gup** command update binaries installed by "go install" to the latest version. It also provides subcommands for manipulating binaries under \$GOPATH/bin (\$GOBIN). It is a cross-platform software that runs on Windows, Mac and Linux.
99
![sample](./doc/img/sample.png)
10+
11+
gup command will notify you on your desktop whether the update was successful or unsuccessful after the update was finished.
12+
![success](./doc/img/notify_success.png)
13+
![warning](./doc/img/notify_warning.png)
14+
1015
# How to install
1116
### Step.1 Install golang
1217
gup command only supports installation with `$ go install`. If you does not have the golang development environment installed on your system, please install golang from the [golang official website](https://go.dev/doc/install).

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/nao1215/gup/internal/assets"
45
"github.com/nao1215/gup/internal/print"
56
"github.com/spf13/cobra"
67
)
@@ -13,6 +14,7 @@ If you update all binaries, just run '$ gup update'`,
1314

1415
// Execute run gup process.
1516
func Execute() {
17+
assets.DeployIconIfNeeded()
1618
if err := rootCmd.Execute(); err != nil {
1719
print.Err(err)
1820
}

cmd/update.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/nao1215/gup/internal/goutil"
12+
"github.com/nao1215/gup/internal/notify"
1213
"github.com/nao1215/gup/internal/print"
1314
"github.com/nao1215/gup/internal/slice"
1415
"github.com/spf13/cobra"
@@ -65,6 +66,7 @@ func update(pkgs []goutil.Package, dryRun bool) int {
6566
if dryRun {
6667
if err := dryRunManager.StartDryRunMode(); err != nil {
6768
print.Err(fmt.Errorf("can not change to dry run mode: %w", err))
69+
notify.Warn("gup", "Can not change to dry run mode")
6870
return 1
6971
}
7072
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP,
@@ -99,6 +101,12 @@ func update(pkgs []goutil.Package, dryRun bool) int {
99101
}
100102
close(signals)
101103
}
104+
105+
if result == 0 {
106+
notify.Info("gup", "All update success")
107+
} else {
108+
notify.Warn("gup", "Some package can't update")
109+
}
102110
return result
103111
}
104112

doc/img/notify_success.png

7.94 KB
Loading

doc/img/notify_warning.png

8.97 KB
Loading

doc/ja/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
[![UnitTest](https://github.com/nao1215/gup/actions/workflows/unit_test.yml/badge.svg)](https://github.com/nao1215/gup/actions/workflows/unit_test.yml)
33
[![reviewdog](https://github.com/nao1215/gup/actions/workflows/reviewdog.yml/badge.svg)](https://github.com/nao1215/gup/actions/workflows/reviewdog.yml)
44
# gupとは
5-
**gup**コマンドは、"go install"でインストールしたバイナリを最新版にアップデートします。gupは、\$GOPATH/bin (\$GOBIN) 以下にあるバイナリをするためのサブコマンドも提供しています。
5+
**gup**コマンドは、"go install"でインストールしたバイナリを最新版にアップデートします。gupは、\$GOPATH/bin (\$GOBIN) 以下にあるバイナリをするためのサブコマンドも提供しています。クロスプラットホームソフトであり、Windows, Mac, Linux で動作します。
66
![sample](../img/sample.png)
7+
8+
gupコマンドはアップデートが終わった後、成功したか失敗したかをデスクトップ通知します。
9+
![success](..//img/notify_success.png)
10+
![warning](../img/notify_warning.png)
711
# インストール方法
812
### Step.1 前準備
913
現在は、" $ go install"によるインストールのみをサポートしています。そのため、golangの開発環境をシステムにインストールしていない場合、[golang公式サイト](https://go.dev/doc/install)からgolangをインストールしてください。

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ go 1.17
44

55
require (
66
github.com/fatih/color v1.13.0
7+
github.com/gen2brain/beeep v0.0.0-20210529141713-5586760f0cc1
78
github.com/mattn/go-colorable v0.1.12
89
github.com/spf13/cobra v1.4.0
910
)
1011

1112
require (
13+
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
14+
github.com/godbus/dbus/v5 v5.0.3 // indirect
15+
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c // indirect
16+
github.com/gopherjs/gopherwasm v1.1.0 // indirect
1217
github.com/inconshreveable/mousetrap v1.0.0 // indirect
1318
github.com/mattn/go-isatty v0.0.14 // indirect
19+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
1420
github.com/spf13/pflag v1.0.5 // indirect
21+
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
1522
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
1623
)

go.sum

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
22
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
33
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
4+
github.com/gen2brain/beeep v0.0.0-20210529141713-5586760f0cc1 h1:Xh9mvwEmhbdXlRSsgn+N0zj/NqnKvpeqL08oKDHln2s=
5+
github.com/gen2brain/beeep v0.0.0-20210529141713-5586760f0cc1/go.mod h1:ElSskYZe3oM8kThaHGJ+kiN2yyUMVXMZ7WxF9QqLDS8=
6+
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
7+
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
8+
github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME=
9+
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
10+
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c h1:16eHWuMGvCjSfgRJKqIzapE78onvvTbdi1rMkU00lZw=
11+
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
12+
github.com/gopherjs/gopherwasm v1.1.0 h1:fA2uLoctU5+T3OhOn2vYP0DVT6pxc7xhTlBB1paATqQ=
13+
github.com/gopherjs/gopherwasm v1.1.0/go.mod h1:SkZ8z7CWBz5VXbhJel8TxCmAcsQqzgWGR/8nMhyhZSI=
414
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
515
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
616
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
@@ -9,13 +19,18 @@ github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb
919
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
1020
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
1121
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
22+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
23+
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
1224
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
1325
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
1426
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
1527
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
1628
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
29+
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
30+
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
1731
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1832
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
33+
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1934
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2035
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2136
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E=

internal/assets/asset.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package assets
2+
3+
import (
4+
_ "embed"
5+
"fmt"
6+
"os"
7+
"path/filepath"
8+
9+
"github.com/nao1215/gup/internal/config"
10+
"github.com/nao1215/gup/internal/file"
11+
"github.com/nao1215/gup/internal/print"
12+
)
13+
14+
//go:embed information.png
15+
var inforIcon []byte
16+
17+
//go:embed warning.png
18+
var warningIcon []byte
19+
20+
// DeployIconIfNeeded make icon file for notification.
21+
func DeployIconIfNeeded() {
22+
if !file.IsDir(assetsDirPath()) {
23+
if err := os.MkdirAll(assetsDirPath(), 0775); err != nil {
24+
print.Err(fmt.Errorf("%s: %w", "can not make assets directory", err))
25+
return
26+
}
27+
}
28+
29+
if !file.IsFile(InfoIconPath()) {
30+
err := os.WriteFile(InfoIconPath(), inforIcon, 0664)
31+
if err != nil {
32+
print.Warn(err)
33+
}
34+
}
35+
if !file.IsFile(WarningIconPath()) {
36+
err := os.WriteFile(WarningIconPath(), warningIcon, 0664)
37+
if err != nil {
38+
print.Warn(err)
39+
}
40+
}
41+
}
42+
43+
// InfoIconPath return absolute path of information.png
44+
func InfoIconPath() string {
45+
return filepath.Join(assetsDirPath(), "information.png")
46+
}
47+
48+
// WarningIconPath return absolute path of information.png
49+
func WarningIconPath() string {
50+
return filepath.Join(assetsDirPath(), "warning.png")
51+
}
52+
53+
// assetsDirPath return absolute path of assets directory
54+
func assetsDirPath() string {
55+
return filepath.Join(config.DirPath(), "assets")
56+
}

0 commit comments

Comments
 (0)