Compare commits

..

No commits in common. "main" and "v0.3.0" have entirely different histories.
main ... v0.3.0

15 changed files with 59 additions and 212 deletions

View File

@ -1,29 +0,0 @@
name: CI
on:
push:
branches: [ "main" ]
paths:
- '**.go'
pull_request:
branches: [ "main" ]
paths:
- '**.go'
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
timeout-minutes: 3
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- name: Run golangci-lint
run: golangci-lint run ./...

View File

@ -1,54 +0,0 @@
run:
# timeout for analysis, e.g. 30s, 3m, default is 1m
timeout: 3m
# exclude test files
tests: true
linters:
# Set to true runs only fast linters.
# Good option for 'lint on save', pre-commit hook or CI.
fast: true
disable-all: true
enable:
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- gofmt
- gofumpt
- misspell
- unparam
- gosec
- asciicheck
- errname
- gci
- godot
- goimports
- revive
linters-settings:
gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'
misspell:
locale: UK
errcheck:
check-type-assertions: true
issues:
max-same-issues: 0
max-issues-per-linter: 0
exclude-use-default: false
exclude:
# gosec: Duplicated errcheck checks
- G104
# gosec: integer overflow conversion int -> uint32
- G115

View File

@ -11,19 +11,6 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
- [x]
# [0.4.1] - 2025-04-05
### Changed
- `-loglevel` flag is now of type string. It accepts any one of trace, debug, info, warn, error, fatal or panic.
- It defaults to warn.
# [0.3.1] - 2025-03-31
### Fixed
- The CLI now uses `os.UserConfigDir()` to load the default *config.toml*, which should respect `$XDG_CONFIG_HOME`. See [UserConfigDir](https://pkg.go.dev/os#UserConfigDir)
# [0.2.1] - 2024-11-07
### Fixed

View File

@ -9,10 +9,10 @@ For an outline of past/future changes refer to: [CHANGELOG](CHANGELOG.md)
## Tested against
- Basic 1.1.1.8
- Banana 2.1.1.8
- Potato 3.1.1.8
- Matrix 1.0.1.2
- Basic 1.0.8.4
- Banana 2.0.6.4
- Potato 3.0.2.4
- Matrix 1.0.0.3
## Requirements
@ -84,7 +84,7 @@ Command line flags will override values in a config.toml.
## `Script files`
The vbantxt CLI accepts a single string request or an array of string requests. This means you can pass scripts stored in files.
The vbantxt-cli utility accepts a single string request or an array of string requests. This means you can pass scripts stored in files.
For example, in Windows with Powershell you could:
@ -116,22 +116,8 @@ vbantxt -s=streamname "Point(ASIO128.IN[2],ASIO128.OUT[1]).dBGain = -8"
## `Logging`
The `-loglevel` flag allows you to control the verbosity of the application's logging output.
Log level may be set by passing the `-l` flag with a number from 0 up to 6 where
Acceptable values for this flag are:
0 = Panic, 1 = Fatal, 2 = Error, 3 = Warning, 4 = Info, 5 = Debug, 6 = Trace
- `trace`
- `debug`
- `info`
- `warn`
- `error`
- `fatal`
- `panic`
For example, to set the log level to `debug`, you can use:
```
vbantxt -s=streamname -loglevel=debug "bus[0].eq.on=1 bus[1].gain=-12.8"
```
The default log level is `warn` if the flag is not specified.
Log level defaults to Warning level.

View File

@ -1,4 +1,3 @@
// Package main provides the configuration loading functionality for the vbantxt application.
package main
import (

View File

@ -35,4 +35,5 @@ func TestLoadConfig_Errors(t *testing.T) {
assert.ErrorContains(t, err, tc.err)
})
}
}

View File

@ -5,25 +5,15 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"time"
"github.com/onyx-and-iris/vbantxt"
log "github.com/sirupsen/logrus"
)
type opts struct {
host string
port int
streamname string
bps int
channel int
ratelimit int
configPath string
loglevel string
}
func exit(err error) {
_, _ = fmt.Fprintf(os.Stderr, "Error: %s\n", err)
_, _ = fmt.Fprintf(os.Stderr, "Error: %s", err)
os.Exit(1)
}
@ -32,7 +22,7 @@ func main() {
host string
port int
streamname string
loglevel string
loglevel int
configPath string
bps int
channel int
@ -46,61 +36,43 @@ func main() {
flag.StringVar(&streamname, "streamname", "Command1", "stream name for text requests")
flag.StringVar(&streamname, "s", "Command1", "stream name for text requests (shorthand)")
flag.IntVar(&bps, "bps", 256000, "vban bps")
flag.IntVar(&bps, "b", 256000, "vban bps (shorthand)")
flag.IntVar(&bps, "bps", 0, "vban bps")
flag.IntVar(&bps, "b", 0, "vban bps (shorthand)")
flag.IntVar(&channel, "channel", 0, "vban channel")
flag.IntVar(&channel, "c", 0, "vban channel (shorthand)")
flag.IntVar(&ratelimit, "ratelimit", 20, "request ratelimit in milliseconds")
flag.IntVar(&ratelimit, "r", 20, "request ratelimit in milliseconds (shorthand)")
configDir, err := os.UserConfigDir()
homeDir, err := os.UserHomeDir()
if err != nil {
exit(err)
}
defaultConfigPath := filepath.Join(configDir, "vbantxt", "config.toml")
defaultConfigPath := filepath.Join(homeDir, ".config", "vbantxt", "config.toml")
flag.StringVar(&configPath, "config", defaultConfigPath, "config path")
flag.StringVar(&configPath, "C", defaultConfigPath, "config path (shorthand)")
flag.StringVar(&loglevel, "loglevel", "warn", "log level")
flag.StringVar(&loglevel, "l", "warn", "log level (shorthand)")
flag.IntVar(&loglevel, "loglevel", int(log.WarnLevel), "log level")
flag.IntVar(&loglevel, "l", int(log.WarnLevel), "log level (shorthand)")
flag.Parse()
level, err := log.ParseLevel(loglevel)
if err != nil {
exit(fmt.Errorf("invalid log level: %s", loglevel))
}
log.SetLevel(level)
o := opts{
host: host,
port: port,
streamname: streamname,
bps: bps,
channel: channel,
ratelimit: ratelimit,
configPath: configPath,
loglevel: loglevel,
if slices.Contains(log.AllLevels, log.Level(loglevel)) {
log.SetLevel(log.Level(loglevel))
}
// Load the config only if the host, port, and streamname flags are not provided.
// This allows the user to override the config values with command line flags.
if !flagsPassed([]string{"host", "h", "port", "p", "streamname", "s"}) {
config, err := loadConfig(configPath)
if err != nil {
exit(err)
}
o.host = config.Host
o.port = config.Port
o.streamname = config.Streamname
host = config.Host
port = config.Port
streamname = config.Streamname
}
log.Debugf("opts: %+v", o)
client, closer, err := createClient(o)
client, err := createClient(host, port, streamname, bps, channel, ratelimit)
if err != nil {
exit(err)
}
defer closer()
defer client.Close()
for _, arg := range flag.Args() {
err := client.Send(arg)
@ -110,24 +82,16 @@ func main() {
}
}
// createClient creates a new vban client with the provided options.
func createClient(o opts) (*vbantxt.VbanTxt, func(), error) {
func createClient(host string, port int, streamname string, bps, channel, ratelimit int) (*vbantxt.VbanTxt, error) {
client, err := vbantxt.New(
o.host,
o.port,
o.streamname,
vbantxt.WithBPSOpt(o.bps),
vbantxt.WithChannel(o.channel),
vbantxt.WithRateLimit(time.Duration(o.ratelimit)*time.Millisecond))
host,
port,
streamname,
vbantxt.WithBPSOpt(bps),
vbantxt.WithChannel(channel),
vbantxt.WithRateLimit(time.Duration(ratelimit)*time.Millisecond))
if err != nil {
return nil, nil, err
return nil, err
}
closer := func() {
if err := client.Close(); err != nil {
log.Error(err)
}
}
return client, closer, err
return client, err
}

View File

@ -1,4 +1,3 @@
// Package vbantxt provides utilities for handling VBAN text errors.
package vbantxt
// Error is used to define sentinel errors.

10
go.mod
View File

@ -1,18 +1,16 @@
module github.com/onyx-and-iris/vbantxt
go 1.23.0
toolchain go1.24.1
go 1.19
require (
github.com/BurntSushi/toml v1.5.0
github.com/sirupsen/logrus v1.9.3
github.com/BurntSushi/toml v1.2.1
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.9.0
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

11
go.sum
View File

@ -1,19 +1,18 @@
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -9,14 +9,14 @@ import (
// Option is a functional option type that allows us to configure the VbanTxt.
type Option func(*VbanTxt)
// WithRateLimit is a functional option to set the ratelimit for requests.
// WithRateLimit is a functional option to set the ratelimit for requests
func WithRateLimit(ratelimit time.Duration) Option {
return func(vt *VbanTxt) {
vt.ratelimit = ratelimit
}
}
// WithBPSOpt is a functional option to set the bps index for {VbanTxt}.packet.
// WithBPSOpt is a functional option to set the bps index for {VbanTxt}.packet
func WithBPSOpt(bps int) Option {
return func(vt *VbanTxt) {
bpsIndex := indexOf(BpsOpts, bps)
@ -28,7 +28,7 @@ func WithBPSOpt(bps int) Option {
}
}
// WithChannel is a functional option to set the channel for {VbanTxt}.packet.
// WithChannel is a functional option to set the channel for {VbanTxt}.packet
func WithChannel(channel int) Option {
return func(vt *VbanTxt) {
vt.packet.channel = channel

View File

@ -13,12 +13,9 @@ const (
headerSz = 4 + 1 + 1 + 1 + 1 + 16 + 4
)
// BpsOpts defines the available baud rate options.
var BpsOpts = []int{
0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250,
var BpsOpts = []int{0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250,
38400, 57600, 115200, 128000, 230400, 250000, 256000, 460800, 921600,
1000000, 1500000, 2000000, 3000000,
}
1000000, 1500000, 2000000, 3000000}
type packet struct {
streamname []byte
@ -42,17 +39,17 @@ func newPacket(streamname string) packet {
}
}
// sr defines the samplerate for the request.
// sr defines the samplerate for the request
func (p *packet) sr() byte {
return byte(vbanProtocolTxt + p.bpsIndex)
}
// nbc defines the channel of the request.
// nbc defines the channel of the request
func (p *packet) nbc() byte {
return byte(p.channel)
}
// header returns a fully formed packet header.
// header returns a fully formed packet header
func (p *packet) header() []byte {
p.hbuf.Reset()
p.hbuf.WriteString("VBAN")
@ -65,7 +62,7 @@ func (p *packet) header() []byte {
return p.hbuf.Bytes()
}
// bumpFrameCounter increments the frame counter by 1.
// bumpFrameCounter increments the frame counter by 1
func (p *packet) bumpFrameCounter() {
x := binary.LittleEndian.Uint32(p.framecounter)
binary.LittleEndian.PutUint32(p.framecounter, x+1)

View File

@ -7,12 +7,12 @@ import (
log "github.com/sirupsen/logrus"
)
// udpConn represents the UDP client.
// udpConn represents the UDP client
type udpConn struct {
conn *net.UDPConn
}
// newUDPConn returns a UDP client.
// newUDPConn returns a UDP client
func newUDPConn(host string, port int) (udpConn, error) {
udpAddr, err := net.ResolveUDPAddr("udp4", fmt.Sprintf("%s:%d", host, port))
if err != nil {
@ -27,7 +27,7 @@ func newUDPConn(host string, port int) (udpConn, error) {
return udpConn{conn: conn}, nil
}
// Write implements the io.WriteCloser interface.
// Write implements the io.WriteCloser interface
func (u udpConn) Write(buf []byte) (int, error) {
n, err := u.conn.Write(buf)
if err != nil {
@ -38,7 +38,7 @@ func (u udpConn) Write(buf []byte) (int, error) {
return n, nil
}
// Close implements the io.WriteCloser interface.
// Close implements the io.WriteCloser interface
func (u udpConn) Close() error {
err := u.conn.Close()
if err != nil {

View File

@ -49,7 +49,7 @@ func (vt VbanTxt) Send(cmd string) error {
return nil
}
// Close is responsible for closing the UDP Client connection.
// Close is responsible for closing the UDP Client connection
func (vt VbanTxt) Close() error {
err := vt.udpConn.Close()
if err != nil {

View File

@ -28,14 +28,14 @@ func run(t *testing.T, client *vbantxt.VbanTxt, script []byte) {
}
func TestSendVm(t *testing.T) {
client, err := vbantxt.New("localhost", 6980, "onyx")
client, err := vbantxt.New("vm.local", 6980, "onyx")
require.NoError(t, err)
run(t, client, vm)
}
func TestSendMatrix(t *testing.T) {
client, err := vbantxt.New("localhost", 6990, "onyx")
client, err := vbantxt.New("vm.local", 6990, "onyx")
require.NoError(t, err)
run(t, client, matrix)