-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.go
50 lines (42 loc) · 891 Bytes
/
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
package main
import (
"fmt"
"io"
"os"
"github.com/spf13/cobra"
"github.com/nakabonne/pbgopy/commands"
)
type app struct {
rootCmd *cobra.Command
stdout io.Writer
stderr io.Writer
}
func newApp(name, desc string, stdout, stderr io.Writer) *app {
a := &app{
rootCmd: &cobra.Command{
Use: name,
Short: desc,
},
stdout: stdout,
stderr: stderr,
}
return a
}
func (a *app) addCommands(cmds ...*cobra.Command) {
for _, cmd := range cmds {
a.rootCmd.AddCommand(cmd)
}
}
func main() {
a := newApp("pbgopy", "Copy and paste between devices", os.Stdout, os.Stderr)
a.addCommands(
commands.NewCopyCommand(a.stdout, a.stderr),
commands.NewPasteCommand(a.stdout, a.stderr),
commands.NewServeCommand(a.stdout, a.stderr),
commands.NewVersionCommand(a.stderr),
)
if err := a.rootCmd.Execute(); err != nil {
fmt.Fprintln(a.stderr, err)
os.Exit(1)
}
}