mirror of
https://github.com/onyx-and-iris/vbantxt.git
synced 2025-04-28 17:03:52 +01:00
Compare commits
No commits in common. "main" and "v0.3.1" have entirely different histories.
13
CHANGELOG.md
13
CHANGELOG.md
@ -11,19 +11,6 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
|||||||
|
|
||||||
- [x]
|
- [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
|
# [0.2.1] - 2024-11-07
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
30
README.md
30
README.md
@ -9,10 +9,10 @@ For an outline of past/future changes refer to: [CHANGELOG](CHANGELOG.md)
|
|||||||
|
|
||||||
## Tested against
|
## Tested against
|
||||||
|
|
||||||
- Basic 1.1.1.8
|
- Basic 1.0.8.4
|
||||||
- Banana 2.1.1.8
|
- Banana 2.0.6.4
|
||||||
- Potato 3.1.1.8
|
- Potato 3.0.2.4
|
||||||
- Matrix 1.0.1.2
|
- Matrix 1.0.0.3
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ Command line flags will override values in a config.toml.
|
|||||||
|
|
||||||
## `Script files`
|
## `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:
|
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`
|
## `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`
|
Log level defaults to Warning level.
|
||||||
- `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.
|
|
||||||
|
@ -5,25 +5,15 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/onyx-and-iris/vbantxt"
|
"github.com/onyx-and-iris/vbantxt"
|
||||||
log "github.com/sirupsen/logrus"
|
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) {
|
func exit(err error) {
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "Error: %s\n", err)
|
_, _ = fmt.Fprintf(os.Stderr, "Error: %s", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +22,7 @@ func main() {
|
|||||||
host string
|
host string
|
||||||
port int
|
port int
|
||||||
streamname string
|
streamname string
|
||||||
loglevel string
|
loglevel int
|
||||||
configPath string
|
configPath string
|
||||||
bps int
|
bps int
|
||||||
channel int
|
channel int
|
||||||
@ -46,8 +36,8 @@ func main() {
|
|||||||
flag.StringVar(&streamname, "streamname", "Command1", "stream name for text requests")
|
flag.StringVar(&streamname, "streamname", "Command1", "stream name for text requests")
|
||||||
flag.StringVar(&streamname, "s", "Command1", "stream name for text requests (shorthand)")
|
flag.StringVar(&streamname, "s", "Command1", "stream name for text requests (shorthand)")
|
||||||
|
|
||||||
flag.IntVar(&bps, "bps", 256000, "vban bps")
|
flag.IntVar(&bps, "bps", 0, "vban bps")
|
||||||
flag.IntVar(&bps, "b", 256000, "vban bps (shorthand)")
|
flag.IntVar(&bps, "b", 0, "vban bps (shorthand)")
|
||||||
flag.IntVar(&channel, "channel", 0, "vban channel")
|
flag.IntVar(&channel, "channel", 0, "vban channel")
|
||||||
flag.IntVar(&channel, "c", 0, "vban channel (shorthand)")
|
flag.IntVar(&channel, "c", 0, "vban channel (shorthand)")
|
||||||
flag.IntVar(&ratelimit, "ratelimit", 20, "request ratelimit in milliseconds")
|
flag.IntVar(&ratelimit, "ratelimit", 20, "request ratelimit in milliseconds")
|
||||||
@ -60,47 +50,29 @@ func main() {
|
|||||||
defaultConfigPath := filepath.Join(configDir, "vbantxt", "config.toml")
|
defaultConfigPath := filepath.Join(configDir, "vbantxt", "config.toml")
|
||||||
flag.StringVar(&configPath, "config", defaultConfigPath, "config path")
|
flag.StringVar(&configPath, "config", defaultConfigPath, "config path")
|
||||||
flag.StringVar(&configPath, "C", defaultConfigPath, "config path (shorthand)")
|
flag.StringVar(&configPath, "C", defaultConfigPath, "config path (shorthand)")
|
||||||
flag.StringVar(&loglevel, "loglevel", "warn", "log level")
|
flag.IntVar(&loglevel, "loglevel", int(log.WarnLevel), "log level")
|
||||||
flag.StringVar(&loglevel, "l", "warn", "log level (shorthand)")
|
flag.IntVar(&loglevel, "l", int(log.WarnLevel), "log level (shorthand)")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
level, err := log.ParseLevel(loglevel)
|
if slices.Contains(log.AllLevels, log.Level(loglevel)) {
|
||||||
if err != nil {
|
log.SetLevel(log.Level(loglevel))
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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"}) {
|
if !flagsPassed([]string{"host", "h", "port", "p", "streamname", "s"}) {
|
||||||
config, err := loadConfig(configPath)
|
config, err := loadConfig(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exit(err)
|
exit(err)
|
||||||
}
|
}
|
||||||
|
host = config.Host
|
||||||
o.host = config.Host
|
port = config.Port
|
||||||
o.port = config.Port
|
streamname = config.Streamname
|
||||||
o.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 {
|
if err != nil {
|
||||||
exit(err)
|
exit(err)
|
||||||
}
|
}
|
||||||
defer closer()
|
defer client.Close()
|
||||||
|
|
||||||
for _, arg := range flag.Args() {
|
for _, arg := range flag.Args() {
|
||||||
err := client.Send(arg)
|
err := client.Send(arg)
|
||||||
@ -110,24 +82,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// createClient creates a new vban client with the provided options.
|
func createClient(host string, port int, streamname string, bps, channel, ratelimit int) (*vbantxt.VbanTxt, error) {
|
||||||
func createClient(o opts) (*vbantxt.VbanTxt, func(), error) {
|
|
||||||
client, err := vbantxt.New(
|
client, err := vbantxt.New(
|
||||||
o.host,
|
host,
|
||||||
o.port,
|
port,
|
||||||
o.streamname,
|
streamname,
|
||||||
vbantxt.WithBPSOpt(o.bps),
|
vbantxt.WithBPSOpt(bps),
|
||||||
vbantxt.WithChannel(o.channel),
|
vbantxt.WithChannel(channel),
|
||||||
vbantxt.WithRateLimit(time.Duration(o.ratelimit)*time.Millisecond))
|
vbantxt.WithRateLimit(time.Duration(ratelimit)*time.Millisecond))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return client, err
|
||||||
closer := func() {
|
|
||||||
if err := client.Close(); err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return client, closer, err
|
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -13,6 +13,6 @@ require (
|
|||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
golang.org/x/sys v0.32.0 // indirect
|
golang.org/x/sys v0.31.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -12,8 +12,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
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=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
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.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||||
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sys v0.31.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 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
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=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
@ -28,14 +28,14 @@ func run(t *testing.T, client *vbantxt.VbanTxt, script []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSendVm(t *testing.T) {
|
func TestSendVm(t *testing.T) {
|
||||||
client, err := vbantxt.New("localhost", 6980, "onyx")
|
client, err := vbantxt.New("vm.local", 6980, "onyx")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
run(t, client, vm)
|
run(t, client, vm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSendMatrix(t *testing.T) {
|
func TestSendMatrix(t *testing.T) {
|
||||||
client, err := vbantxt.New("localhost", 6990, "onyx")
|
client, err := vbantxt.New("vm.local", 6990, "onyx")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
run(t, client, matrix)
|
run(t, client, matrix)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user