switch makeosc to urfave/cli

This commit is contained in:
2025-09-27 09:55:09 -05:00
parent e519f2d53c
commit ce5e65e8f8
+36 -10
View File
@@ -1,13 +1,14 @@
package main package main
import ( import (
"context"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
osc "github.com/jwetzell/osc-go" osc "github.com/jwetzell/osc-go"
"github.com/spf13/cobra" "github.com/urfave/cli/v3"
) )
func main() { func main() {
@@ -16,18 +17,43 @@ func main() {
var Types []string var Types []string
var Slip bool var Slip bool
var rootCmd = &cobra.Command{ cmd := &cli.Command{
Use: "makeosc", Name: "makeosc",
Run: func(cmd *cobra.Command, args []string) { Usage: "make osc bytes",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "address",
Value: "",
Usage: "OSC address",
Destination: &Address,
Required: true,
},
&cli.StringSliceFlag{
Name: "arg",
Usage: "OSC args",
Destination: &Args,
},
&cli.StringSliceFlag{
Name: "type",
Usage: "OSC types",
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 {
make(Address, Args, Types, Slip) make(Address, Args, Types, Slip)
return nil
}, },
} }
rootCmd.Flags().StringVar(&Address, "address", "", "OSC address")
rootCmd.Flags().StringArrayVar(&Args, "arg", []string{}, "OSC args") if err := cmd.Run(context.Background(), os.Args); err != nil {
rootCmd.Flags().StringArrayVar(&Types, "type", []string{}, "OSC types") panic(err)
rootCmd.Flags().BoolVar(&Slip, "slip", false, "whether to slip encode the OSC Message bytes") }
rootCmd.MarkFlagRequired("address")
rootCmd.Execute()
} }
func argToTypedArg(rawArg string, oscType string) osc.OSCArg { func argToTypedArg(rawArg string, oscType string) osc.OSCArg {