-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
146 lines (140 loc) · 3.97 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//go:build (windows && amd64) || (linux && amd64) || (darwin && amd64) || (darwin && arm64)
package main
import (
"log"
"os"
"github.com/pkg/browser"
"github.com/urfave/cli/v2"
)
func main() {
// removes timestamp from `log` https://stackoverflow.com/a/48630122
// TODO think about if I really need this
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))
app := &cli.App{
Name: "telltail",
Version: version,
Usage: "Telltail is a universal clipboard for text. And this CLI lets you configure it for your device.",
Commands: []*cli.Command{
{
Name: "install",
Category: "Install",
Usage: "Install one of Telltail services",
Subcommands: []*cli.Command{
{
Name: "center",
Usage: "Installs Center. Only one device in your Tailscale network needs to install this, and the device should mostly be running when you work.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "auth-key",
Usage: "A reusable, non-ephermal key you obtained from https://login.tailscale.com/admin/settings/keys",
Required: true,
},
},
Action: func(cc *cli.Context) error {
err := guardArgsNonEmpty(cc, "auth-key")
if err != nil {
return err
}
return installCenter(cc.String("auth-key"))
},
}, {
Name: "sync",
Usage: "Installs Sync. If you want Ctrl+C and Ctrl+V (or Command+C and Command+V in macOS) to use universal clipboard, then you should install it on this device.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "tailnet",
Usage: "You can find your tailnet name in here: https://login.tailscale.com/admin/dns",
Required: true,
},
&cli.StringFlag{
Name: "device",
Usage: "A unique name for this device. Tailscale would've assinged a name and an IP to this device. You could use that for example.",
Required: true,
},
},
Action: func(cc *cli.Context) error {
err := guardArgsNonEmpty(cc, "tailnet", "device")
if err != nil {
return err
}
return installSync(installSyncParams{tailnet: cc.String("tailnet"), device: cc.String("device")})
},
},
},
},
{
Name: "uninstall",
Category: "Install",
Usage: "Uninstall one of Telltail services",
Subcommands: []*cli.Command{
{
Name: "center",
Usage: "Uninstalls Center",
Action: func(cc *cli.Context) error {
return uninstallCenter()
},
}, {
Name: "sync",
Usage: "Uninstalls Sync",
Action: func(cc *cli.Context) error {
return uninstallSync()
},
},
},
},
{
Name: "start",
Category: "Manage",
Usage: "Start a service",
Action: func(cc *cli.Context) error {
return manageService(cc.Args().Get(0), startService)
},
},
{
Name: "stop",
Category: "Manage",
Usage: "Stop a service. (This will not stop it from running on system restart. Use uninstall for that.)",
Action: func(cc *cli.Context) error {
return manageService(cc.Args().Get(0), stopService)
},
},
{
Name: "restart",
Category: "Manage",
Usage: "Restart a service",
Action: func(cc *cli.Context) error {
return manageService(cc.Args().Get(0), restartService)
},
},
{
Name: "edit",
Category: "Manage",
Usage: "Edit config of a service",
Subcommands: []*cli.Command{
{
Name: "center-auth-key",
Action: func(cc *cli.Context) error {
return editCenterAuthKey()
},
},
},
},
{
Name: "guide",
Category: "Help",
Usage: "Opens documentation guide in your browser",
Action: func(cc *cli.Context) error {
return browser.OpenURL("https://guide-on.gitbook.io/telltail")
},
},
{
Name: "help",
Category: "Help",
Usage: "Opens this help",
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}