Skip to content

Commit

Permalink
Add a cli (example/real world usage)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmshal committed Sep 18, 2016
1 parent 049fec7 commit f160d73
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
vendor/
vendor/*
!vendor/vendor.json
test/
3 changes: 3 additions & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin/
vendor/*
!vendor/vendor.json
2 changes: 2 additions & 0 deletions cli/build.sh
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
95 changes: 95 additions & 0 deletions cli/main.go
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)
}
25 changes: 25 additions & 0 deletions cli/vendor/vendor.json
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"
}
2 changes: 1 addition & 1 deletion toast.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func init() {
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
$APP_ID = '{{if .AppID}}{{.AppID}}{{else}}io.github.jacobmarshall.go-toast{{end}}'
$APP_ID = '{{if .AppID}}{{.AppID}}{{else}}io.github.go-toast.toast{{end}}'
$template = @"
<toast>
Expand Down
2 changes: 1 addition & 1 deletion vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"revisionTime": "2013-12-21T20:05:32Z"
}
],
"rootPath": "github.com/jacobmarshall/go-toast"
"rootPath": "github.com/go-toast/toast"
}

0 comments on commit f160d73

Please sign in to comment.