From d6d4ac4419e5b74c39abdc126ad6406f523ba303 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Sat, 9 May 2026 14:06:33 -0500 Subject: [PATCH] stop using destination --- cmd/makeosc/makeosc.go | 38 ++++++++++----------- cmd/receiveosc/receiveosc.go | 56 +++++++++++++++---------------- cmd/sendosc/sendosc.go | 65 ++++++++++++++++-------------------- 3 files changed, 72 insertions(+), 87 deletions(-) diff --git a/cmd/makeosc/makeosc.go b/cmd/makeosc/makeosc.go index 4bbfc5c..e28cff0 100644 --- a/cmd/makeosc/makeosc.go +++ b/cmd/makeosc/makeosc.go @@ -12,41 +12,37 @@ import ( ) func main() { - var Address string - var Args []string - var Types []string - var Slip bool cmd := &cli.Command{ Name: "makeosc", Usage: "make osc bytes", Flags: []cli.Flag{ &cli.StringFlag{ - Name: "address", - Value: "", - Usage: "OSC address", - Destination: &Address, - Required: true, + Name: "address", + Value: "", + Usage: "OSC address", + Required: true, }, &cli.StringSliceFlag{ - Name: "arg", - Usage: "OSC args", - Destination: &Args, + Name: "arg", + Usage: "OSC args", }, &cli.StringSliceFlag{ - Name: "type", - Usage: "OSC types", - Destination: &Types, + Name: "type", + Usage: "OSC types", }, &cli.BoolFlag{ - Name: "slip", - Value: false, - Usage: "whether to slip encode the OSC Message bytes", - Destination: &Slip, + Name: "slip", + Value: false, + Usage: "whether to slip encode the OSC Message bytes", }, }, Action: func(ctx context.Context, cmd *cli.Command) error { - make(Address, Args, Types, Slip) + address := cmd.String("address") + args := cmd.StringSlice("arg") + types := cmd.StringSlice("type") + slip := cmd.Bool("slip") + makeMsg(address, args, types, slip) return nil }, } @@ -158,7 +154,7 @@ func slipEncode(bytes []byte) []byte { return encodedBytes } -func make(address string, args []string, types []string, slip bool) { +func makeMsg(address string, args []string, types []string, slip bool) { oscMessage := osc.OSCMessage{ Address: address, diff --git a/cmd/receiveosc/receiveosc.go b/cmd/receiveosc/receiveosc.go index 9773b12..cf34f65 100644 --- a/cmd/receiveosc/receiveosc.go +++ b/cmd/receiveosc/receiveosc.go @@ -12,33 +12,25 @@ import ( ) func main() { - var IP string - var Port int32 - var Protocol string - var Format string - var Slip bool cmd := &cli.Command{ Name: "receiveosc", Usage: "receive OSC messages via UDP or TCP", Flags: []cli.Flag{ &cli.StringFlag{ - Name: "ip", - Usage: "ip to receive OSC messages on", - Value: "0.0.0.0", - Destination: &IP, + Name: "ip", + Usage: "ip to receive OSC messages on", + Value: "0.0.0.0", }, &cli.Int32Flag{ - Name: "port", - Usage: "port to receive OSC messages on", - Destination: &Port, - Value: 8888, + Name: "port", + Usage: "port to receive OSC messages on", + Value: 8888, }, &cli.StringFlag{ - Name: "protocol", - Usage: "protocol to use to receive (tcp or udp)", - Value: "udp", - Destination: &Protocol, + Name: "protocol", + Usage: "protocol to use to receive (tcp or udp)", + Value: "udp", Validator: func(flag string) error { if flag != "udp" && flag != "tcp" { return fmt.Errorf("protocol must be either 'udp' or 'tcp'") @@ -47,10 +39,9 @@ func main() { }, }, &cli.StringFlag{ - Name: "format", - Usage: "format for messages to be output in ('json')", - Value: "json", - Destination: &Format, + Name: "format", + Usage: "format for messages to be output in ('json')", + Value: "json", Validator: func(flag string) error { if flag != "json" { return fmt.Errorf("format must be 'json'") @@ -59,22 +50,27 @@ func main() { }, }, &cli.BoolFlag{ - Name: "slip", - Value: false, - Usage: "whether to slip encode the OSC Message bytes", - Destination: &Slip, + Name: "slip", + Value: false, + Usage: "whether to slip encode the OSC Message bytes", }, }, Action: func(ctx context.Context, cmd *cli.Command) error { - netAddress := fmt.Sprintf("%s:%d", IP, Port) - switch Protocol { + ip := cmd.String("ip") + port := cmd.Int32("port") + protocol := cmd.String("protocol") + format := cmd.String("format") + slip := cmd.Bool("slip") + + netAddress := fmt.Sprintf("%s:%d", ip, port) + switch protocol { case "udp": - listenUDP(netAddress, Format) + listenUDP(netAddress, format) case "tcp": - if !Slip { + if !slip { return fmt.Errorf("OSC 1.0 over TCP is not supported yet") } - listenTCP(netAddress, Slip, Format) + listenTCP(netAddress, slip, format) } return nil }, diff --git a/cmd/sendosc/sendosc.go b/cmd/sendosc/sendosc.go index 4360cb1..8a7d76e 100644 --- a/cmd/sendosc/sendosc.go +++ b/cmd/sendosc/sendosc.go @@ -15,35 +15,25 @@ import ( ) func main() { - var Host string - var Port int32 - var Address string - var Protocol string - var Args []string - var Types []string - var Slip bool cmd := &cli.Command{ Name: "sendosc", Usage: "send OSC messages via UDP or TCP", Flags: []cli.Flag{ &cli.StringFlag{ - Name: "host", - Usage: "host to send OSC message to", - Destination: &Host, - Required: true, + Name: "host", + Usage: "host to send OSC message to", + Required: true, }, &cli.Int32Flag{ - Name: "port", - Usage: "port to send OSC message to", - Destination: &Port, - Required: true, + Name: "port", + Usage: "port to send OSC message to", + Required: true, }, &cli.StringFlag{ - Name: "protocol", - Usage: "protocol to use to send (tcp or udp)", - Value: "udp", - Destination: &Protocol, + Name: "protocol", + Usage: "protocol to use to send (tcp or udp)", + Value: "udp", Validator: func(flag string) error { if flag != "udp" && flag != "tcp" { return fmt.Errorf("protocol must be either 'udp' or 'tcp'") @@ -52,32 +42,35 @@ func main() { }, }, &cli.StringFlag{ - Name: "address", - Usage: "OSC address", - Destination: &Address, - Required: true, + Name: "address", + Usage: "OSC address", + Required: true, }, &cli.StringSliceFlag{ - Name: "arg", - Usage: "OSC args", - Value: []string{}, - Destination: &Args, + Name: "arg", + Usage: "OSC args", + Value: []string{}, }, &cli.StringSliceFlag{ - Name: "type", - Usage: "OSC types", - Value: []string{}, - Destination: &Types, + Name: "type", + Usage: "OSC types", + Value: []string{}, }, &cli.BoolFlag{ - Name: "slip", - Value: false, - Usage: "whether to slip encode the OSC Message bytes", - Destination: &Slip, + Name: "slip", + Value: false, + Usage: "whether to slip encode the OSC Message bytes", }, }, Action: func(ctx context.Context, cmd *cli.Command) error { - send(Host, Port, Address, Args, Types, Protocol, Slip) + host := cmd.String("host") + port := cmd.Int32("port") + address := cmd.String("address") + args := cmd.StringSlice("arg") + types := cmd.StringSlice("type") + protocol := cmd.String("protocol") + slip := cmd.Bool("slip") + send(host, port, address, args, types, protocol, slip) return nil }, }