This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
121 lines (97 loc) · 2.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"fmt"
"os"
"github.com/codegangsta/cli"
"github.com/mitsuse/arcus/application"
)
const (
name = "arcus"
version = "0.1.3"
description = "A command-line tool to send a message to devices via Pushbullet."
author = "Tomoya Kose (mitsuse)"
email = "[email protected]"
variableToken = "ARCUS_ACCESS_TOKEN"
)
func main() {
app := cli.NewApp()
app.Name = name
app.Version = version
app.Usage = description
app.Author = author
app.Email = email
app.Commands = []cli.Command{
newSendCommand(),
newListCommand(),
}
app.Run(os.Args)
}
func newListCommand() cli.Command {
command := cli.Command{
Name: "list",
ShortName: "l",
Usage: "List devices that can be pushed to",
Action: func(c *cli.Context) {
token := getToken()
devices, err := application.ListDevices(token)
if err != nil {
printError(err)
return
}
for _, d := range devices {
if !d.Pushable {
continue
}
fmt.Println(d.Nickname)
}
},
}
return command
}
func newSendCommand() cli.Command {
command := cli.Command{
Name: "send",
ShortName: "s",
Usage: "Send a message or a file",
Flags: []cli.Flag{
cli.StringFlag{
Name: "device,d",
Value: "",
Usage: "The name of target device",
},
cli.StringFlag{
Name: "title,t",
Value: "",
Usage: "The title of the message or file to be sent",
},
cli.StringFlag{
Name: "message,m",
Value: "",
Usage: "The message to be sent",
},
cli.StringFlag{
Name: "location,l",
Value: "",
Usage: "The path of file or link to be sent",
},
},
Action: func(c *cli.Context) {
token := getToken()
title := c.String("title")
message := c.String("message")
location := c.String("location")
device := c.String("device")
if err := application.Send(token, title, message, location, device); err != nil {
printError(err)
return
}
},
}
return command
}
func getToken() string {
return os.Getenv(variableToken)
}
func printError(err error) {
fmt.Fprintf(os.Stderr, "%s: %s\n", name, err)
}