-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a cli (example/real world usage)
- Loading branch information
Showing
7 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
vendor/ | ||
vendor/* | ||
!vendor/vendor.json | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bin/ | ||
vendor/* | ||
!vendor/vendor.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GOOS=windows GOARCH=amd64 go build -o ./bin/toast64.exe ./*.go | ||
GOOS=windows GOARCH=386 go build -o ./bin/toast32.exe ./*.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"gopkg.in/toast.v1" | ||
"gopkg.in/urfave/cli.v1" | ||
) | ||
|
||
func main() { | ||
app := cli.NewApp() | ||
|
||
app.Name = "toast" | ||
app.Usage = "Windows 10 toasts" | ||
app.Version = "v1" | ||
app.Compiled = time.Now() | ||
app.Authors = []cli.Author{ | ||
cli.Author{ | ||
Name: "Jacob Marshall", | ||
Email: "[email protected]", | ||
}, | ||
} | ||
|
||
app.Flags = []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "app-id, id", | ||
Usage: "the app identifier (used for grouping multiple toasts)", | ||
}, | ||
cli.StringFlag{ | ||
Name: "title, t", | ||
Usage: "the main toast title/heading", | ||
}, | ||
cli.StringFlag{ | ||
Name: "message, m", | ||
Usage: "the toast's main message (new lines as separator)", | ||
}, | ||
cli.StringFlag{ | ||
Name: "icon, i", | ||
Usage: "the app icon path (displays to the left of the toast)", | ||
}, | ||
cli.StringSliceFlag{ | ||
Name: "action, a", | ||
Usage: "optional action button", | ||
}, | ||
cli.StringSliceFlag{ | ||
Name: "action-type, at", | ||
Usage: "the type of action button", | ||
}, | ||
cli.StringSliceFlag{ | ||
Name: "action-arg, aa", | ||
Usage: "the action button argument", | ||
}, | ||
} | ||
|
||
app.Action = func(c *cli.Context) error { | ||
appID := c.String("app-id") | ||
title := c.String("title") | ||
message := c.String("message") | ||
icon := c.String("icon") | ||
|
||
var actions []toast.Action | ||
actionTexts := c.StringSlice("action") | ||
actionTypes := c.StringSlice("action-type") | ||
actionArgs := c.StringSlice("action-arg") | ||
|
||
for index, actionLabel := range actionTexts { | ||
var actionType string = "protocol" | ||
var actionArg string | ||
if len(actionTypes) > index { | ||
actionType = actionTypes[index] | ||
} | ||
if len(actionArgs) > index { | ||
actionArg = actionArgs[index] | ||
} | ||
actions = append(actions, toast.Action{ | ||
Type: actionType, | ||
Label: actionLabel, | ||
Arguments: actionArg, | ||
}) | ||
} | ||
|
||
notification := &toast.Notification{ | ||
AppID: appID, | ||
Title: title, | ||
Message: message, | ||
Icon: icon, | ||
Actions: actions, | ||
} | ||
|
||
return notification.Push() | ||
} | ||
|
||
app.Run(os.Args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"comment": "", | ||
"ignore": "test", | ||
"package": [ | ||
{ | ||
"checksumSHA1": "gcLub3oB+u4QrOJZcYmk/y2AP4k=", | ||
"path": "github.com/nu7hatch/gouuid", | ||
"revision": "179d4d0c4d8d407a32af483c2354df1d2c91e6c3", | ||
"revisionTime": "2013-12-21T20:05:32Z" | ||
}, | ||
{ | ||
"checksumSHA1": "XuaxAgPWq9xtwvNiRWw/OsaGK5I=", | ||
"path": "gopkg.in/toast.v1", | ||
"revision": "049fec7c3ab02cbc413be76c65bb966aa020f46c", | ||
"revisionTime": "2016-09-17T22:57:05Z" | ||
}, | ||
{ | ||
"checksumSHA1": "/1TzqyoYSSdEkFrZG20XoNGwD8o=", | ||
"path": "gopkg.in/urfave/cli.v1", | ||
"revision": "a14d7d367bc02b1f57d88de97926727f2d936387", | ||
"revisionTime": "2016-08-29T00:43:50Z" | ||
} | ||
], | ||
"rootPath": "github.com/go-toast/toast/cli" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters