mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-07-26 10:28:42 +00:00
switch sendosc to urfave/cli
This commit is contained in:
+62
-15
@@ -1,14 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
osc "github.com/jwetzell/osc-go"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -20,23 +22,68 @@ func main() {
|
||||
var Types []string
|
||||
var Slip bool
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "sendosc",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmd := &cli.Command{
|
||||
Name: "makeosc",
|
||||
Usage: "make osc bytes",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "host",
|
||||
Usage: "host to send OSC message to",
|
||||
Destination: &Host,
|
||||
Required: true,
|
||||
},
|
||||
&cli.Int32Flag{
|
||||
Name: "port",
|
||||
Usage: "port to send OSC message to",
|
||||
Destination: &Port,
|
||||
Required: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "protocol",
|
||||
Usage: "protocol to use to send (tcp or udp)",
|
||||
Value: "udp",
|
||||
Destination: &Protocol,
|
||||
Validator: func(flag string) error {
|
||||
if flag != "udp" && flag != "tcp" {
|
||||
return fmt.Errorf("protocol must be either 'udp' or 'tcp'")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "address",
|
||||
Usage: "OSC address",
|
||||
Destination: &Address,
|
||||
Required: true,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "arg",
|
||||
Usage: "OSC args",
|
||||
Value: []string{},
|
||||
Destination: &Args,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "type",
|
||||
Usage: "OSC types",
|
||||
Value: []string{},
|
||||
Destination: &Types,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "slip",
|
||||
Value: false,
|
||||
Usage: "whether to slip encode the OSC Message bytes",
|
||||
Destination: &Slip,
|
||||
},
|
||||
},
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
send(Host, Port, Address, Args, Types, Protocol, Slip)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
rootCmd.Flags().StringVar(&Host, "host", "", "host to send OSC message to")
|
||||
rootCmd.Flags().Int32Var(&Port, "port", 9999, "port to send OSC message to")
|
||||
rootCmd.Flags().StringVar(&Address, "address", "", "OSC address")
|
||||
rootCmd.Flags().StringVar(&Protocol, "protocol", "udp", "protocol to use to send (tcp or udp)")
|
||||
rootCmd.Flags().StringArrayVar(&Args, "arg", []string{}, "OSC args")
|
||||
rootCmd.Flags().StringArrayVar(&Types, "type", []string{}, "OSC types")
|
||||
rootCmd.Flags().BoolVar(&Slip, "slip", false, "whether to slip encode the OSC Message bytes")
|
||||
rootCmd.MarkFlagRequired("host")
|
||||
rootCmd.MarkFlagRequired("port")
|
||||
rootCmd.MarkFlagRequired("address")
|
||||
rootCmd.Execute()
|
||||
|
||||
if err := cmd.Run(context.Background(), os.Args); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func argToTypedArg(rawArg string, oscType string) osc.OSCArg {
|
||||
|
||||
@@ -2,7 +2,10 @@ module github.com/jwetzell/osc-go
|
||||
|
||||
go 1.23.1
|
||||
|
||||
require github.com/spf13/cobra v1.9.1
|
||||
require (
|
||||
github.com/spf13/cobra v1.9.1
|
||||
github.com/urfave/cli/v3 v3.4.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
|
||||
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
|
||||
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
|
||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/urfave/cli/v3 v3.4.1 h1:1M9UOCy5bLmGnuu1yn3t3CB4rG79Rtoxuv1sPhnm6qM=
|
||||
github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
Reference in New Issue
Block a user