-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
136 lines (128 loc) · 3.05 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
package main
import (
"os"
"github.com/72nd/osc-utility/src"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "osc-utility",
Usage: "utlity for working with OSC",
Version: "1.2.0",
Authors: []*cli.Author{
{
Name: "72nd",
Email: "[email protected]",
},
},
Action: func(c *cli.Context) error {
_ = cli.ShowCommandHelp(c, c.Command.Name)
return nil
},
Commands: []*cli.Command{
{
Name: "message",
Aliases: []string{"msg", "m"},
Usage: "send a message to a OSC server",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "host",
Usage: "host of the OSC server",
Value: "localhost",
},
&cli.IntFlag{
Name: "port",
Aliases: []string{"p"},
Usage: "port of the OSC server",
Value: 9000,
},
&cli.StringFlag{
Name: "address",
Aliases: []string{"adr", "a"},
Usage: "address of the message",
},
&cli.StringFlag{
Name: "string",
Aliases: []string{"str", "s"},
Usage: "string argument (separate multiple values by comma)",
},
&cli.StringFlag{
Name: "int, i",
Aliases: []string{"int", "i"},
Usage: "integer 32 argument (separate multiple values by comma)",
},
&cli.StringFlag{
Name: "float, f",
Aliases: []string{"float", "f"},
Usage: "float 32 argument (separate multiple values by comma)",
},
&cli.StringFlag{
Name: "bool, b",
Aliases: []string{"b"},
Usage: "boolean argument (separate multiple values by comma)",
},
},
Action: messageAction,
},
{
Name: "server",
Aliases: []string{"srv", "s"},
Usage: "OSC server on localhost, prints incoming messages",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "host",
Usage: "host to run the server on",
Value: "127.0.0.1",
},
&cli.IntFlag{
Name: "port",
Aliases: []string{"p"},
Usage: "port number to run the server on",
},
},
Action: serverAction,
},
},
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
func messageAction(c *cli.Context) error {
msg := oscutility.Message{}
if c.String("host") == "localhost" {
logrus.Info("using default host (localhost)")
}
msg.Host = c.String("host")
msg.Port = c.Int("port")
if c.Int("port") == 0 {
logrus.Error("no port specified (--port)")
return nil
}
if c.String("address") == "" {
logrus.Error("no address specified (--address)")
return nil
}
msg.Address = c.String("address")
msg.SetBooleans(c.String("bool"))
msg.SetStrings(c.String("string"))
msg.SetIntegers(c.String("int"))
msg.SetFloats(c.String("float"))
msg.Send()
return nil
}
func serverAction(c *cli.Context) error {
srv := oscutility.Server{}
srv.Host = c.String("host")
if srv.Host == "127.0.0.1" {
logrus.Info("using default host (127.0.0.1)")
}
srv.Port = c.Int("port")
if c.Int("port") == 0 {
logrus.Error("no port specified (--port)")
return nil
}
srv.Serve()
return nil
}