mirror of
https://github.com/onyx-and-iris/vbantxt.git
synced 2026-04-07 17:53:30 +00:00
Compare commits
46 Commits
add-load-f
...
v0.6.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d9924ff58 | |||
| 00acafa290 | |||
| f97d241f64 | |||
| 87ea26ab03 | |||
| 331d4e2f9a | |||
| d21dfb9481 | |||
| 510d43ca33 | |||
| acac22f70e | |||
| b568767f86 | |||
| 08909b6b66 | |||
| c6d03e87d7 | |||
| 0d0dbedbcd | |||
|
|
ecd16545ab | ||
|
|
abdc50bf1f | ||
| bf22881227 | |||
|
|
1473c53dea | ||
|
|
6f10f3ce20 | ||
|
|
f803a38619 | ||
|
|
862f127d54 | ||
|
|
500a1c886a | ||
|
|
707f2c9a2c | ||
|
|
9c9242bae4 | ||
|
|
b56b4afcbf | ||
|
|
c08019a063 | ||
|
|
29a503ce8f | ||
|
|
22529a0b39 | ||
|
|
a153830d3f | ||
|
|
e7736f383b | ||
|
|
458ea95da0 | ||
|
|
805a3250fc | ||
|
|
defcbbc8a7 | ||
|
|
19011b0b34 | ||
|
|
923e741455 | ||
|
|
5a0cf42347 | ||
|
|
0f9dad3015 | ||
|
|
9106a19486 | ||
|
|
84ef1904fc | ||
| f9ca8a05db | |||
| 9844d22c46 | |||
|
|
e7e158981b | ||
| b60909e6ec | |||
| 9a15ad98a8 | |||
| b8fa4d5be0 | |||
| 64c1cb8fbe | |||
| eeb789003b | |||
| 4fd190bc4e |
13
.github/workflows/golang-ci.yml
vendored
13
.github/workflows/golang-ci.yml
vendored
@@ -2,11 +2,11 @@ name: CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "main" ]
|
branches: ['main']
|
||||||
paths:
|
paths:
|
||||||
- '**.go'
|
- '**.go'
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: ['main']
|
||||||
paths:
|
paths:
|
||||||
- '**.go'
|
- '**.go'
|
||||||
jobs:
|
jobs:
|
||||||
@@ -23,7 +23,8 @@ jobs:
|
|||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.24'
|
go-version: '1.24'
|
||||||
- name: Install golangci-lint
|
- name: golangci-lint
|
||||||
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
uses: golangci/golangci-lint-action@v9
|
||||||
- name: Run golangci-lint
|
with:
|
||||||
run: golangci-lint run ./...
|
version: v2.6.0
|
||||||
|
args: --config .golangci.yml
|
||||||
|
|||||||
157
.golangci.yml
157
.golangci.yml
@@ -1,54 +1,125 @@
|
|||||||
|
version: '2'
|
||||||
|
|
||||||
run:
|
run:
|
||||||
# timeout for analysis, e.g. 30s, 3m, default is 1m
|
|
||||||
timeout: 3m
|
timeout: 3m
|
||||||
# exclude test files
|
|
||||||
tests: true
|
tests: true
|
||||||
|
go: '1.24'
|
||||||
|
|
||||||
linters:
|
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:
|
enable:
|
||||||
- gosimple
|
# Default enabled linters
|
||||||
- govet
|
- errcheck # Check for unchecked errors
|
||||||
- ineffassign
|
- govet # Go's built-in vetting tool
|
||||||
- staticcheck
|
- ineffassign # Detect ineffectual assignments
|
||||||
- unused
|
- staticcheck # Advanced static analysis
|
||||||
- gofmt
|
- unused # Check for unused code
|
||||||
- gofumpt
|
# Additional useful linters
|
||||||
- misspell
|
- misspell # Detect common misspellings
|
||||||
- unparam
|
- unparam # Check for unused function parameters
|
||||||
- gosec
|
- gosec # Security checks
|
||||||
- asciicheck
|
- asciicheck # Check for non-ASCII characters
|
||||||
- errname
|
- errname # Check error variable names
|
||||||
- gci
|
- godot # Check for missing periods in comments
|
||||||
- godot
|
- revive # Highly configurable linter for style and correctness
|
||||||
- goimports
|
- gocritic # Detect code issues and suggest improvements
|
||||||
- revive
|
- gocyclo # Check for cyclomatic complexity
|
||||||
|
- dupl # Check for code duplication
|
||||||
|
- predeclared # Check for shadowing of predeclared identifiers
|
||||||
|
- copyloopvar # Check for loop variable capture in goroutines
|
||||||
|
- errorlint # Check for common mistakes in error handling
|
||||||
|
- goconst # Check for repeated strings that could be constants
|
||||||
|
- gosmopolitan # Check for non-portable code
|
||||||
|
|
||||||
linters-settings:
|
settings:
|
||||||
gofmt:
|
misspell:
|
||||||
rewrite-rules:
|
locale: UK
|
||||||
- pattern: 'interface{}'
|
|
||||||
replacement: 'any'
|
|
||||||
- pattern: 'a[b:len(a)]'
|
|
||||||
replacement: 'a[b:]'
|
|
||||||
|
|
||||||
misspell:
|
errcheck:
|
||||||
locale: UK
|
check-type-assertions: true
|
||||||
|
check-blank: true
|
||||||
|
|
||||||
errcheck:
|
revive:
|
||||||
check-type-assertions: true
|
rules:
|
||||||
|
# Code quality and style
|
||||||
|
- name: exported
|
||||||
|
arguments:
|
||||||
|
- 'checkPrivateReceivers'
|
||||||
|
- 'sayRepetitiveInsteadOfStutters'
|
||||||
|
- name: var-naming
|
||||||
|
- name: package-comments
|
||||||
|
- name: range-val-in-closure
|
||||||
|
- name: time-naming
|
||||||
|
- name: context-as-argument
|
||||||
|
- name: context-keys-type
|
||||||
|
- name: dot-imports
|
||||||
|
- name: empty-block
|
||||||
|
- name: error-return
|
||||||
|
- name: error-strings
|
||||||
|
- name: error-naming
|
||||||
|
- name: if-return
|
||||||
|
- name: increment-decrement
|
||||||
|
- name: indent-error-flow
|
||||||
|
- name: receiver-naming
|
||||||
|
- name: redefines-builtin-id
|
||||||
|
- name: superfluous-else
|
||||||
|
- name: unexported-return
|
||||||
|
- name: unreachable-code
|
||||||
|
- name: unused-parameter
|
||||||
|
- name: var-declaration
|
||||||
|
- name: blank-imports
|
||||||
|
- name: range
|
||||||
|
|
||||||
|
# Disabled rules (can be enabled if needed)
|
||||||
|
# - name: line-length-limit
|
||||||
|
# arguments: [120]
|
||||||
|
# - name: function-length
|
||||||
|
# arguments: [50, 0]
|
||||||
|
# - name: cyclomatic
|
||||||
|
# arguments: [10]
|
||||||
|
|
||||||
|
gosec:
|
||||||
|
excludes:
|
||||||
|
- G104 # Duplicated errcheck checks
|
||||||
|
- G115 # integer overflow conversion int -> uint32
|
||||||
|
|
||||||
|
exclusions:
|
||||||
|
warn-unused: false
|
||||||
|
rules:
|
||||||
|
# Exclude some linters from running on tests files.
|
||||||
|
- path: _test\.go
|
||||||
|
linters:
|
||||||
|
- gocyclo
|
||||||
|
- errcheck
|
||||||
|
- dupl
|
||||||
|
- gosec
|
||||||
|
|
||||||
|
# Formatters configuration
|
||||||
|
formatters:
|
||||||
|
# Enable specific formatters
|
||||||
|
enable:
|
||||||
|
- gofumpt # Stricter gofmt alternative
|
||||||
|
- goimports # Organizes imports
|
||||||
|
- gci # Controls import order/grouping
|
||||||
|
- golines # Enforces line length
|
||||||
|
|
||||||
|
# Formatter-specific settings
|
||||||
|
settings:
|
||||||
|
goimports:
|
||||||
|
local-prefixes: [github.com/onyx-and-iris/vbantxt]
|
||||||
|
|
||||||
|
gci:
|
||||||
|
# Define import sections order
|
||||||
|
sections:
|
||||||
|
- standard # Standard library
|
||||||
|
- default # Everything else
|
||||||
|
- prefix(github.com/onyx-and-iris/vbantxt) # Current module
|
||||||
|
|
||||||
|
gofumpt:
|
||||||
|
extra-rules: true # Enable additional formatting rules
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
max-same-issues: 0
|
# Limit the number of same issues reported to avoid spam
|
||||||
max-issues-per-linter: 0
|
max-same-issues: 50
|
||||||
exclude-use-default: false
|
|
||||||
exclude:
|
# Limit the number of issues per linter to keep output manageable
|
||||||
# gosec: Duplicated errcheck checks
|
max-issues-per-linter: 100
|
||||||
- G104
|
|
||||||
# gosec: integer overflow conversion int -> uint32
|
|
||||||
- G115
|
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ builds:
|
|||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
- windows
|
- windows
|
||||||
|
- darwin
|
||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
|
- arm64
|
||||||
|
|
||||||
archives:
|
archives:
|
||||||
- formats: ['tar.gz']
|
- formats: ['tar.gz']
|
||||||
@@ -46,6 +48,7 @@ changelog:
|
|||||||
exclude:
|
exclude:
|
||||||
- '^docs:'
|
- '^docs:'
|
||||||
- '^test:'
|
- '^test:'
|
||||||
|
- '^chore:'
|
||||||
|
|
||||||
release:
|
release:
|
||||||
footer: >-
|
footer: >-
|
||||||
|
|||||||
15
CHANGELOG.md
15
CHANGELOG.md
@@ -11,18 +11,29 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
|||||||
|
|
||||||
- [x]
|
- [x]
|
||||||
|
|
||||||
|
# [0.6.0] - 2025-02-14
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- streamname length validation added to {packet} factory method.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- {packet}.bspIndex now defaults to *indexOf(BpsOpts, 256000)*.
|
||||||
|
- this doesn't affect the CLI which already defaulted to 256000.
|
||||||
|
- WithBPSOpt and WithChannel functional options now log at warn level if passed out of bounds value. They will fallback to valid defaults.
|
||||||
|
|
||||||
# [0.5.0] - 2025-06-25
|
# [0.5.0] - 2025-06-25
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- it's now possible to load configuration from environment variables. See [Environment Variables]()
|
- it's now possible to load configuration from environment variables. See [Environment Variables](https://github.com/onyx-and-iris/vbantxt/tree/main?tab=readme-ov-file#environment-variables)
|
||||||
- --version/-v command
|
- --version/-v command
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- shortname for --host flag is now -H.
|
- shortname for --host flag is now -H.
|
||||||
- shortname for --channel flag is now -n.
|
- shortname for --channel flag is now -n.
|
||||||
- toml loader no longer requires a `[connection]` table. See [TOML Config]()
|
- toml loader no longer requires a `[connection]` table. See [TOML Config](https://github.com/onyx-and-iris/vbantxt/tree/main?tab=readme-ov-file#toml-config)
|
||||||
|
|
||||||
|
|
||||||
# [0.4.1] - 2025-04-05
|
# [0.4.1] - 2025-04-05
|
||||||
|
|||||||
79
README.md
79
README.md
@@ -7,23 +7,34 @@ Send Voicemeeter/Matrix vban requests.
|
|||||||
|
|
||||||
For an outline of past/future changes refer to: [CHANGELOG](CHANGELOG.md)
|
For an outline of past/future changes refer to: [CHANGELOG](CHANGELOG.md)
|
||||||
|
|
||||||
## Tested against
|
---
|
||||||
|
|
||||||
- Basic 1.1.1.8
|
## Table of Contents
|
||||||
- Banana 2.1.1.8
|
|
||||||
- Potato 3.1.1.8
|
- [Installation](#installation)
|
||||||
- Matrix 1.0.1.2
|
- [VBANTXT Package](#vbantxt-package)
|
||||||
|
- [VBANTXT CLI](#vbantxt-cli)
|
||||||
|
- [License](#license)
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- [Voicemeeter](https://voicemeeter.com/) or [Matrix](https://vb-audio.com/Matrix/)
|
- [Voicemeeter](https://voicemeeter.com/) or [Matrix](https://vb-audio.com/Matrix/)
|
||||||
- Go 1.18 or greater (if you want to compile yourself, otherwise check `Releases`)
|
- Go 1.18 or greater (a binary is available in [Releases](https://github.com/onyx-and-iris/vbantxt/releases))
|
||||||
|
|
||||||
|
## Tested against
|
||||||
|
|
||||||
|
- Basic 1.1.1.9
|
||||||
|
- Banana 2.1.1.9
|
||||||
|
- Potato 3.1.1.9
|
||||||
|
- Matrix 1.0.1.2
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## `Use`
|
## `VBANTXT Package`
|
||||||
|
|
||||||
`go get github.com/onyx-and-iris/vbantxt`
|
```console
|
||||||
|
go get github.com/onyx-and-iris/vbantxt
|
||||||
|
```
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -55,35 +66,55 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## `Command Line`
|
## `VBANTXT CLI`
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
```console
|
||||||
|
go install github.com/onyx-and-iris/vbantxt/cmd/vbantxt@latest
|
||||||
|
```
|
||||||
|
|
||||||
|
### Use
|
||||||
|
|
||||||
|
Simply pass your vban commands as command line arguments:
|
||||||
|
|
||||||
|
```console
|
||||||
|
vbantxt "strip[0].mute=1 strip[1].mono=1"
|
||||||
|
```
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
#### Flags
|
#### Flags
|
||||||
|
|
||||||
- --host/-H: defaults to localhost
|
```console
|
||||||
- --port/-p: defaults to 6980
|
FLAGS
|
||||||
- --streamname/-s: defaults to Command1
|
-H, --host STRING VBAN host (default: localhost)
|
||||||
- --config/-C: defaults to `$XDG_CONFIG_HOME / vbantxt / config.toml`
|
-p, --port INT VBAN port (default: 6980)
|
||||||
- --loglevel/-l: defaults to warn
|
-s, --streamname STRING VBAN stream name (default: Command1)
|
||||||
- --version/-v: print the vbantxt version and exit
|
-b, --bps INT VBAN BPS (default: 256000)
|
||||||
|
-n, --channel INT VBAN channel (default: 0)
|
||||||
|
-r, --ratelimit INT VBAN rate limit (ms) (default: 20)
|
||||||
|
-C, --config STRING Path to the configuration file (default: $XDG_CONFIG_HOME/vbantxt/config.toml)
|
||||||
|
-l, --loglevel STRING Log level (debug, info, warn, error, fatal, panic) (default: warn)
|
||||||
|
-v, --version Show version information
|
||||||
|
```
|
||||||
|
|
||||||
For example:
|
Pass --host, --port and --streamname as flags on the root command, for example:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
vbantxt --host="gamepc.local" --port=6980 --streamname=Command1 "strip[0].mute=1 strip[1].mono=1"
|
vbantxt --host=localhost --port=6980 --streamname=Command1 --help
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Environment Variables
|
#### Environment Variables
|
||||||
|
|
||||||
Load the following values from your environment:
|
All flags have corresponding environment variables, prefixed with `VBANTXT_`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
export VBANTXT_HOST=localhost
|
export VBANTXT_HOST=localhost
|
||||||
export VBANTXT_PORT=6980
|
export VBANTXT_PORT=6980
|
||||||
export VBANTXT_STREAMNAME=onyx
|
export VBANTXT_STREAMNAME=Command1
|
||||||
```
|
```
|
||||||
|
|
||||||
Flags will override environment variables.
|
Flags will override environment variables.
|
||||||
@@ -93,8 +124,9 @@ Flags will override environment variables.
|
|||||||
By default the config loader will look for a config in:
|
By default the config loader will look for a config in:
|
||||||
|
|
||||||
- $XDG_CONFIG_HOME / vbantxt / config.toml (see [os.UserConfigDir](https://pkg.go.dev/os#UserConfigDir))
|
- $XDG_CONFIG_HOME / vbantxt / config.toml (see [os.UserConfigDir](https://pkg.go.dev/os#UserConfigDir))
|
||||||
|
- A custom config path may be passed with the --config/-C flag.
|
||||||
|
|
||||||
A valid config.toml might look like this:
|
All flags have corresponding keys in the config file, for example:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
host="gamepc.local"
|
host="gamepc.local"
|
||||||
@@ -102,8 +134,6 @@ port=6980
|
|||||||
streamname="Command1"
|
streamname="Command1"
|
||||||
```
|
```
|
||||||
|
|
||||||
A custom config path may be passed with the --config/-C flag.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## `Script files`
|
## `Script files`
|
||||||
@@ -162,3 +192,8 @@ vbantxt --loglevel=debug "bus[0].eq.on=1 bus[1].gain=-12.8"
|
|||||||
```
|
```
|
||||||
|
|
||||||
The default log level is `warn` if the flag is not specified.
|
The default log level is `warn` if the flag is not specified.
|
||||||
|
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
`vbantxt` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
||||||
|
|||||||
11
Taskfile.yml
11
Taskfile.yml
@@ -9,6 +9,7 @@ vars:
|
|||||||
|
|
||||||
WINDOWS: '{{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe'
|
WINDOWS: '{{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe'
|
||||||
LINUX: '{{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64'
|
LINUX: '{{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64'
|
||||||
|
MACOS: '{{.BIN_DIR}}/{{.PROGRAM}}_darwin_amd64'
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
default:
|
default:
|
||||||
@@ -22,7 +23,7 @@ tasks:
|
|||||||
cmds:
|
cmds:
|
||||||
- task: build-windows
|
- task: build-windows
|
||||||
- task: build-linux
|
- task: build-linux
|
||||||
|
- task: build-macos
|
||||||
vet:
|
vet:
|
||||||
desc: Vet the code
|
desc: Vet the code
|
||||||
deps: [fmt]
|
deps: [fmt]
|
||||||
@@ -38,11 +39,19 @@ tasks:
|
|||||||
desc: Build the vbantxt project for Windows
|
desc: Build the vbantxt project for Windows
|
||||||
cmds:
|
cmds:
|
||||||
- GOOS=windows GOARCH=amd64 go build -o {{.WINDOWS}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
|
- GOOS=windows GOARCH=amd64 go build -o {{.WINDOWS}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
|
||||||
|
internal: true
|
||||||
|
|
||||||
build-linux:
|
build-linux:
|
||||||
desc: Build the vbantxt project for Linux
|
desc: Build the vbantxt project for Linux
|
||||||
cmds:
|
cmds:
|
||||||
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
|
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
|
||||||
|
internal: true
|
||||||
|
|
||||||
|
build-macos:
|
||||||
|
desc: Build the vbantxt project for macOS
|
||||||
|
cmds:
|
||||||
|
- GOOS=darwin GOARCH=amd64 go build -o {{.MACOS}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
|
||||||
|
internal: true
|
||||||
|
|
||||||
test:
|
test:
|
||||||
desc: Run tests
|
desc: Run tests
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
"github.com/onyx-and-iris/vbantxt"
|
|
||||||
"github.com/peterbourgon/ff/v4"
|
"github.com/peterbourgon/ff/v4"
|
||||||
"github.com/peterbourgon/ff/v4/ffhelp"
|
"github.com/peterbourgon/ff/v4/ffhelp"
|
||||||
"github.com/peterbourgon/ff/v4/fftoml"
|
"github.com/peterbourgon/ff/v4/fftoml"
|
||||||
|
|
||||||
|
"github.com/onyx-and-iris/vbantxt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version string // Version will be set at build time
|
var version string // Version will be set at build time
|
||||||
@@ -32,16 +33,46 @@ type Flags struct {
|
|||||||
Version bool // Version flag
|
Version bool // Version flag
|
||||||
}
|
}
|
||||||
|
|
||||||
func exitOnError(err error) {
|
func (f *Flags) String() string {
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "Error: %s\n", err)
|
return fmt.Sprintf(
|
||||||
os.Exit(1)
|
"Host: %s, Port: %d, Streamname: %s, Bps: %d, Channel: %d, Ratelimit: %dms, ConfigPath: %s, Loglevel: %s",
|
||||||
|
f.Host,
|
||||||
|
f.Port,
|
||||||
|
f.Streamname,
|
||||||
|
f.Bps,
|
||||||
|
f.Channel,
|
||||||
|
f.Ratelimit,
|
||||||
|
f.ConfigPath,
|
||||||
|
f.Loglevel,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var exitCode int
|
||||||
|
|
||||||
|
// Defer exit with the final exit code
|
||||||
|
defer func() {
|
||||||
|
if exitCode != 0 {
|
||||||
|
os.Exit(exitCode)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
closer, err := run()
|
||||||
|
if closer != nil {
|
||||||
|
defer closer()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
exitCode = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// run contains the main application logic and returns a closer function and any error.
|
||||||
|
func run() (func(), error) {
|
||||||
var flags Flags
|
var flags Flags
|
||||||
|
|
||||||
// VBAN specific flags
|
// VBAN specific flags
|
||||||
fs := ff.NewFlagSet("vbantxt")
|
fs := ff.NewFlagSet("vbantxt - A command-line tool for sending text requests over VBAN")
|
||||||
fs.StringVar(&flags.Host, 'H', "host", "localhost", "VBAN host")
|
fs.StringVar(&flags.Host, 'H', "host", "localhost", "VBAN host")
|
||||||
fs.IntVar(&flags.Port, 'p', "port", 6980, "VBAN port")
|
fs.IntVar(&flags.Port, 'p', "port", 6980, "VBAN port")
|
||||||
fs.StringVar(&flags.Streamname, 's', "streamname", "Command1", "VBAN stream name")
|
fs.StringVar(&flags.Streamname, 's', "streamname", "Command1", "VBAN stream name")
|
||||||
@@ -51,13 +82,25 @@ func main() {
|
|||||||
|
|
||||||
configDir, err := os.UserConfigDir()
|
configDir, err := os.UserConfigDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exitOnError(fmt.Errorf("failed to get user config directory: %w", err))
|
return nil, fmt.Errorf("failed to get user config directory: %w", err)
|
||||||
}
|
}
|
||||||
defaultConfigPath := filepath.Join(configDir, "vbantxt", "config.toml")
|
defaultConfigPath := filepath.Join(configDir, "vbantxt", "config.toml")
|
||||||
|
|
||||||
// Configuration file and logging flags
|
// Configuration file and logging flags
|
||||||
fs.StringVar(&flags.ConfigPath, 'C', "config", defaultConfigPath, "Path to the configuration file")
|
fs.StringVar(
|
||||||
fs.StringVar(&flags.Loglevel, 'l', "loglevel", "warn", "Log level (debug, info, warn, error, fatal, panic)")
|
&flags.ConfigPath,
|
||||||
|
'C',
|
||||||
|
"config",
|
||||||
|
defaultConfigPath,
|
||||||
|
"Path to the configuration file",
|
||||||
|
)
|
||||||
|
fs.StringVar(
|
||||||
|
&flags.Loglevel,
|
||||||
|
'l',
|
||||||
|
"loglevel",
|
||||||
|
"warn",
|
||||||
|
"Log level (debug, info, warn, error, fatal, panic)",
|
||||||
|
)
|
||||||
fs.BoolVar(&flags.Version, 'v', "version", "Show version information")
|
fs.BoolVar(&flags.Version, 'v', "version", "Show version information")
|
||||||
|
|
||||||
err = ff.Parse(fs, os.Args[1:],
|
err = ff.Parse(fs, os.Args[1:],
|
||||||
@@ -71,41 +114,48 @@ func main() {
|
|||||||
fmt.Fprintf(os.Stderr, "%s\n", ffhelp.Flags(fs, "vbantxt [flags] <vban commands>"))
|
fmt.Fprintf(os.Stderr, "%s\n", ffhelp.Flags(fs, "vbantxt [flags] <vban commands>"))
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
case err != nil:
|
case err != nil:
|
||||||
exitOnError(fmt.Errorf("failed to parse flags: %w", err))
|
return nil, fmt.Errorf("failed to parse flags: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.Version {
|
if flags.Version {
|
||||||
if version == "" {
|
fmt.Printf("vbantxt version: %s\n", versionFromBuild())
|
||||||
info, ok := debug.ReadBuildInfo()
|
|
||||||
if !ok {
|
|
||||||
exitOnError(errors.New("failed to read build info"))
|
|
||||||
}
|
|
||||||
version = strings.Split(info.Main.Version, "-")[0]
|
|
||||||
}
|
|
||||||
fmt.Printf("vbantxt version: %s\n", version)
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
level, err := log.ParseLevel(flags.Loglevel)
|
level, err := log.ParseLevel(flags.Loglevel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exitOnError(fmt.Errorf("invalid log level: %s", flags.Loglevel))
|
return nil, fmt.Errorf("invalid log level %q", flags.Loglevel)
|
||||||
}
|
}
|
||||||
log.SetLevel(level)
|
log.SetLevel(level)
|
||||||
|
|
||||||
log.Debugf("Loaded configuration: %+v", flags)
|
log.Debugf("Loaded configuration: %s", flags.String())
|
||||||
|
|
||||||
client, closer, err := createClient(&flags)
|
client, closer, err := createClient(&flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exitOnError(err)
|
return nil, fmt.Errorf("failed to create VBAN client: %w", err)
|
||||||
}
|
}
|
||||||
defer closer()
|
|
||||||
|
|
||||||
for _, arg := range fs.GetArgs() {
|
commands := fs.GetArgs()
|
||||||
err := client.Send(arg)
|
if len(commands) == 0 {
|
||||||
if err != nil {
|
return closer, errors.New(
|
||||||
log.Error(err)
|
"no VBAN commands provided; please provide at least one command as an argument",
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendCommands(client, commands)
|
||||||
|
return closer, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// versionFromBuild retrieves the version information from the build metadata.
|
||||||
|
func versionFromBuild() string {
|
||||||
|
if version == "" {
|
||||||
|
info, ok := debug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
return "(unable to read build info)"
|
||||||
|
}
|
||||||
|
version = strings.Split(info.Main.Version, "-")[0]
|
||||||
|
}
|
||||||
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
// createClient creates a new vban client with the provided options.
|
// createClient creates a new vban client with the provided options.
|
||||||
@@ -129,3 +179,12 @@ func createClient(flags *Flags) (*vbantxt.VbanTxt, func(), error) {
|
|||||||
|
|
||||||
return client, closer, err
|
return client, closer, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sendCommands sends the provided VBAN commands using the client and logs any errors that occur.
|
||||||
|
func sendCommands(client *vbantxt.VbanTxt, commands []string) {
|
||||||
|
for _, cmd := range commands {
|
||||||
|
if err := client.Send(cmd); err != nil {
|
||||||
|
log.Errorf("Failed to send command '%s': %v", cmd, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
27
go.mod
27
go.mod
@@ -1,35 +1,36 @@
|
|||||||
module github.com/onyx-and-iris/vbantxt
|
module github.com/onyx-and-iris/vbantxt
|
||||||
|
|
||||||
go 1.23.0
|
go 1.24.2
|
||||||
|
|
||||||
toolchain go1.24.1
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/charmbracelet/log v0.4.2
|
github.com/charmbracelet/log v0.4.2
|
||||||
github.com/peterbourgon/ff/v4 v4.0.0-alpha.4
|
github.com/peterbourgon/ff/v4 v4.0.0-beta.1
|
||||||
github.com/stretchr/testify v1.10.0
|
github.com/stretchr/testify v1.10.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
|
github.com/charmbracelet/colorprofile v0.4.1 // indirect
|
||||||
github.com/charmbracelet/lipgloss v1.1.0 // indirect
|
github.com/charmbracelet/lipgloss v1.1.0 // indirect
|
||||||
github.com/charmbracelet/x/ansi v0.8.0 // indirect
|
github.com/charmbracelet/x/ansi v0.11.6 // indirect
|
||||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
|
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
|
||||||
github.com/charmbracelet/x/term v0.2.1 // indirect
|
github.com/charmbracelet/x/term v0.2.2 // indirect
|
||||||
|
github.com/clipperhouse/displaywidth v0.9.0 // indirect
|
||||||
|
github.com/clipperhouse/stringish v0.1.1 // indirect
|
||||||
|
github.com/clipperhouse/uax29/v2 v2.6.0 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
github.com/go-logfmt/logfmt v0.6.1 // indirect
|
||||||
github.com/kr/pretty v0.1.0 // indirect
|
github.com/kr/pretty v0.1.0 // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
github.com/mattn/go-runewidth v0.0.19 // indirect
|
||||||
github.com/muesli/termenv v0.16.0 // indirect
|
github.com/muesli/termenv v0.16.0 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
|
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/rivo/uniseg v0.4.7 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect
|
||||||
golang.org/x/sys v0.33.0 // indirect
|
golang.org/x/sys v0.41.0 // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
49
go.sum
49
go.sum
@@ -1,42 +1,49 @@
|
|||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
|
github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco3ej+ngLk1kk=
|
||||||
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
|
github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk=
|
||||||
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
|
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
|
||||||
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
|
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
|
||||||
github.com/charmbracelet/log v0.4.2 h1:hYt8Qj6a8yLnvR+h7MwsJv/XvmBJXiueUcI3cIxsyig=
|
github.com/charmbracelet/log v0.4.2 h1:hYt8Qj6a8yLnvR+h7MwsJv/XvmBJXiueUcI3cIxsyig=
|
||||||
github.com/charmbracelet/log v0.4.2/go.mod h1:qifHGX/tc7eluv2R6pWIpyHDDrrb/AG71Pf2ysQu5nw=
|
github.com/charmbracelet/log v0.4.2/go.mod h1:qifHGX/tc7eluv2R6pWIpyHDDrrb/AG71Pf2ysQu5nw=
|
||||||
github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=
|
github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8=
|
||||||
github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
|
github.com/charmbracelet/x/ansi v0.11.6/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ=
|
||||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
|
github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI=
|
||||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
|
github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q=
|
||||||
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
|
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
|
||||||
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
|
github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
|
||||||
|
github.com/clipperhouse/displaywidth v0.9.0 h1:Qb4KOhYwRiN3viMv1v/3cTBlz3AcAZX3+y9OLhMtAtA=
|
||||||
|
github.com/clipperhouse/displaywidth v0.9.0/go.mod h1:aCAAqTlh4GIVkhQnJpbL0T/WfcrJXHcj8C0yjYcjOZA=
|
||||||
|
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
|
||||||
|
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
|
||||||
|
github.com/clipperhouse/uax29/v2 v2.6.0 h1:z0cDbUV+aPASdFb2/ndFnS9ts/WNXgTNNGFoKXuhpos=
|
||||||
|
github.com/clipperhouse/uax29/v2 v2.6.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
|
github.com/go-logfmt/logfmt v0.6.1 h1:4hvbpePJKnIzH1B+8OR/JPbTx37NktoI9LE2QZBBkvE=
|
||||||
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
|
github.com/go-logfmt/logfmt v0.6.1/go.mod h1:EV2pOAQoZaT1ZXZbqDl5hrymndi4SY9ED9/z6CO0XAk=
|
||||||
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
|
||||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
||||||
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
||||||
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
||||||
github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0=
|
github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0=
|
||||||
github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||||
github.com/peterbourgon/ff/v4 v4.0.0-alpha.4 h1:aiqS8aBlF9PsAKeMddMSfbwp3smONCn3UO8QfUg0Z7Y=
|
github.com/peterbourgon/ff/v4 v4.0.0-beta.1 h1:hV8qRu3V7YfiSMsBSfPfdcznAvPQd3jI5zDddSrDoUc=
|
||||||
github.com/peterbourgon/ff/v4 v4.0.0-alpha.4/go.mod h1:H/13DK46DKXy7EaIxPhk2Y0EC8aubKm35nBjBe8AAGc=
|
github.com/peterbourgon/ff/v4 v4.0.0-beta.1/go.mod h1:onQJUKipvCyFmZ1rIYwFAh1BhPOvftb1uhvSI7krNLc=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
|
||||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
@@ -49,11 +56,11 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
|
|||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 h1:Z/6YuSHTLOHfNFdb8zVZomZr7cqNgTJvA8+Qz75D8gU=
|
||||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
golang.org/x/exp v0.0.0-20260112195511-716be5621a96/go.mod h1:nzimsREAkjBCIEFtHiYkrJyT+2uy9YZJB7H1k68CXZU=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
|
||||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
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/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|||||||
10
makefile
10
makefile
@@ -5,24 +5,27 @@ BIN_DIR := bin
|
|||||||
|
|
||||||
WINDOWS=$(BIN_DIR)/$(PROGRAM)_windows_amd64.exe
|
WINDOWS=$(BIN_DIR)/$(PROGRAM)_windows_amd64.exe
|
||||||
LINUX=$(BIN_DIR)/$(PROGRAM)_linux_amd64
|
LINUX=$(BIN_DIR)/$(PROGRAM)_linux_amd64
|
||||||
|
MACOS=$(BIN_DIR)/$(PROGRAM)_darwin_amd64
|
||||||
VERSION=$(shell git describe --tags $(shell git rev-list --tags --max-count=1))
|
VERSION=$(shell git describe --tags $(shell git rev-list --tags --max-count=1))
|
||||||
|
|
||||||
.DEFAULT_GOAL := build
|
.DEFAULT_GOAL := build
|
||||||
|
|
||||||
.PHONY: fmt vet build windows linux test clean
|
.PHONY: fmt vet build windows linux macos test clean
|
||||||
fmt:
|
fmt:
|
||||||
$(GO) fmt ./...
|
$(GO) fmt ./...
|
||||||
|
|
||||||
vet: fmt
|
vet: fmt
|
||||||
$(GO) vet ./...
|
$(GO) vet ./...
|
||||||
|
|
||||||
build: vet windows linux | $(BIN_DIR)
|
build: vet windows linux macos | $(BIN_DIR)
|
||||||
@echo version: $(VERSION)
|
@echo version: $(VERSION)
|
||||||
|
|
||||||
windows: $(WINDOWS)
|
windows: $(WINDOWS)
|
||||||
|
|
||||||
linux: $(LINUX)
|
linux: $(LINUX)
|
||||||
|
|
||||||
|
macos: $(MACOS)
|
||||||
|
|
||||||
|
|
||||||
$(WINDOWS):
|
$(WINDOWS):
|
||||||
env GOOS=windows GOARCH=amd64 go build -v -o $(WINDOWS) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/$(PROGRAM)/
|
env GOOS=windows GOARCH=amd64 go build -v -o $(WINDOWS) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/$(PROGRAM)/
|
||||||
@@ -30,6 +33,9 @@ $(WINDOWS):
|
|||||||
$(LINUX):
|
$(LINUX):
|
||||||
env GOOS=linux GOARCH=amd64 go build -v -o $(LINUX) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/$(PROGRAM)/
|
env GOOS=linux GOARCH=amd64 go build -v -o $(LINUX) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/$(PROGRAM)/
|
||||||
|
|
||||||
|
$(MACOS):
|
||||||
|
env GOOS=darwin GOARCH=amd64 go build -v -o $(MACOS) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/$(PROGRAM)/
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(GO) test ./...
|
$(GO) test ./...
|
||||||
|
|
||||||
|
|||||||
25
option.go
25
option.go
@@ -19,18 +19,37 @@ func WithRateLimit(ratelimit time.Duration) Option {
|
|||||||
// 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 {
|
func WithBPSOpt(bps int) Option {
|
||||||
return func(vt *VbanTxt) {
|
return func(vt *VbanTxt) {
|
||||||
|
defaultBps := BpsOpts[vt.packet.bpsIndex]
|
||||||
|
|
||||||
bpsIndex := indexOf(BpsOpts, bps)
|
bpsIndex := indexOf(BpsOpts, bps)
|
||||||
if bpsIndex == -1 {
|
if bpsIndex == -1 {
|
||||||
log.Warnf("invalid bps value %d, expected one of %v, defaulting to 0", bps, BpsOpts)
|
log.Warnf(
|
||||||
|
"invalid bps value %d, expected one of %v, defaulting to %d",
|
||||||
|
bps,
|
||||||
|
BpsOpts,
|
||||||
|
defaultBps,
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vt.packet.bpsIndex = bpsIndex
|
if bpsIndex > 255 {
|
||||||
|
log.Warnf("bps index %d too large for uint8, defaulting to %d", bpsIndex, defaultBps)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
vt.packet.bpsIndex = uint8(bpsIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 {
|
func WithChannel(channel int) Option {
|
||||||
return func(vt *VbanTxt) {
|
return func(vt *VbanTxt) {
|
||||||
vt.packet.channel = channel
|
if channel < 0 || channel > 255 {
|
||||||
|
log.Warnf(
|
||||||
|
"channel value %d out of range [0,255], defaulting to %d",
|
||||||
|
channel,
|
||||||
|
vt.packet.channel,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
vt.packet.channel = uint8(channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
54
packet.go
54
packet.go
@@ -3,6 +3,7 @@ package vbantxt
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
)
|
)
|
||||||
@@ -21,25 +22,39 @@ var BpsOpts = []int{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type packet struct {
|
type packet struct {
|
||||||
streamname []byte
|
streamname [streamNameSz]byte
|
||||||
bpsIndex int
|
bpsIndex uint8
|
||||||
channel int
|
channel uint8
|
||||||
framecounter []byte
|
framecounter uint32
|
||||||
hbuf *bytes.Buffer
|
hbuf *bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
// newPacket returns a packet struct with default values, framecounter at 0.
|
// newPacket creates a new packet with the given stream name and default values for other fields.
|
||||||
func newPacket(streamname string) packet {
|
// It validates the stream name length and ensures the default baud rate is present in BpsOpts.
|
||||||
streamnameBuf := make([]byte, streamNameSz)
|
func newPacket(streamname string) (packet, error) {
|
||||||
copy(streamnameBuf, streamname)
|
if len(streamname) > streamNameSz {
|
||||||
|
return packet{}, fmt.Errorf(
|
||||||
|
"streamname too long: %d chars, max %d",
|
||||||
|
len(streamname),
|
||||||
|
streamNameSz,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
var streamnameBuf [streamNameSz]byte
|
||||||
|
copy(streamnameBuf[:], streamname)
|
||||||
|
|
||||||
|
bpsIndex := indexOf(BpsOpts, 256000)
|
||||||
|
if bpsIndex == -1 {
|
||||||
|
return packet{}, fmt.Errorf("default baud rate 256000 not found in BpsOpts")
|
||||||
|
}
|
||||||
|
|
||||||
return packet{
|
return packet{
|
||||||
streamname: streamnameBuf,
|
streamname: streamnameBuf,
|
||||||
bpsIndex: 0,
|
bpsIndex: uint8(bpsIndex),
|
||||||
channel: 0,
|
channel: 0,
|
||||||
framecounter: make([]byte, 4),
|
framecounter: 0,
|
||||||
hbuf: bytes.NewBuffer(make([]byte, headerSz)),
|
hbuf: bytes.NewBuffer(make([]byte, 0, headerSz)),
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// sr defines the samplerate for the request.
|
// sr defines the samplerate for the request.
|
||||||
@@ -60,15 +75,20 @@ func (p *packet) header() []byte {
|
|||||||
p.hbuf.WriteByte(byte(0))
|
p.hbuf.WriteByte(byte(0))
|
||||||
p.hbuf.WriteByte(p.nbc())
|
p.hbuf.WriteByte(p.nbc())
|
||||||
p.hbuf.WriteByte(byte(0x10))
|
p.hbuf.WriteByte(byte(0x10))
|
||||||
p.hbuf.Write(p.streamname)
|
p.hbuf.Write(p.streamname[:])
|
||||||
p.hbuf.Write(p.framecounter)
|
|
||||||
|
var frameBytes [4]byte
|
||||||
|
binary.LittleEndian.PutUint32(frameBytes[:], p.framecounter)
|
||||||
|
p.hbuf.Write(frameBytes[:])
|
||||||
|
|
||||||
return p.hbuf.Bytes()
|
return p.hbuf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
// bumpFrameCounter increments the frame counter by 1.
|
// bumpFrameCounter increments the frame counter by 1.
|
||||||
|
// The uint32 will safely wrap to 0 after reaching max value (4,294,967,295),
|
||||||
|
// which is expected behaviour for network protocol sequence numbers.
|
||||||
func (p *packet) bumpFrameCounter() {
|
func (p *packet) bumpFrameCounter() {
|
||||||
x := binary.LittleEndian.Uint32(p.framecounter)
|
p.framecounter++
|
||||||
binary.LittleEndian.PutUint32(p.framecounter, x+1)
|
|
||||||
|
|
||||||
log.Debugf("framecounter: %d", x)
|
log.Debugf("framecounter: %d", p.framecounter)
|
||||||
}
|
}
|
||||||
|
|||||||
23
vbantxt.go
23
vbantxt.go
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
// VbanTxt is used to send VBAN-TXT requests to a distant Voicemeeter/Matrix.
|
// VbanTxt is used to send VBAN-TXT requests to a distant Voicemeeter/Matrix.
|
||||||
type VbanTxt struct {
|
type VbanTxt struct {
|
||||||
udpConn io.WriteCloser
|
conn io.WriteCloser
|
||||||
packet packet
|
packet packet
|
||||||
ratelimit time.Duration
|
ratelimit time.Duration
|
||||||
}
|
}
|
||||||
@@ -16,14 +16,19 @@ type VbanTxt struct {
|
|||||||
// New constructs a fully formed VbanTxt instance. This is the package's entry point.
|
// New constructs a fully formed VbanTxt instance. This is the package's entry point.
|
||||||
// It sets default values for it's fields and then runs the option functions.
|
// It sets default values for it's fields and then runs the option functions.
|
||||||
func New(host string, port int, streamname string, options ...Option) (*VbanTxt, error) {
|
func New(host string, port int, streamname string, options ...Option) (*VbanTxt, error) {
|
||||||
udpConn, err := newUDPConn(host, port)
|
conn, err := newUDPConn(host, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error creating UDP client for (%s:%d): %w", host, port, err)
|
return nil, fmt.Errorf("error creating UDP client for (%s:%d): %w", host, port, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
packet, err := newPacket(streamname)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error creating packet: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
vt := &VbanTxt{
|
vt := &VbanTxt{
|
||||||
udpConn: udpConn,
|
conn: conn,
|
||||||
packet: newPacket(streamname),
|
packet: packet,
|
||||||
ratelimit: time.Duration(20) * time.Millisecond,
|
ratelimit: time.Duration(20) * time.Millisecond,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,10 +39,10 @@ func New(host string, port int, streamname string, options ...Option) (*VbanTxt,
|
|||||||
return vt, nil
|
return vt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send is resonsible for firing each VBAN-TXT request.
|
// Send is responsible for firing each VBAN-TXT request.
|
||||||
// It waits for {vt.ratelimit} time before returning.
|
// It waits for {vt.ratelimit} time before returning.
|
||||||
func (vt VbanTxt) Send(cmd string) error {
|
func (vt *VbanTxt) Send(cmd string) error {
|
||||||
_, err := vt.udpConn.Write(append(vt.packet.header(), []byte(cmd)...))
|
_, err := vt.conn.Write(append(vt.packet.header(), cmd...))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error sending command (%s): %w", cmd, err)
|
return fmt.Errorf("error sending command (%s): %w", cmd, err)
|
||||||
}
|
}
|
||||||
@@ -50,8 +55,8 @@ func (vt VbanTxt) Send(cmd string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close is responsible for closing the UDP Client connection.
|
// Close is responsible for closing the UDP Client connection.
|
||||||
func (vt VbanTxt) Close() error {
|
func (vt *VbanTxt) Close() error {
|
||||||
err := vt.udpConn.Close()
|
err := vt.conn.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error attempting to close UDP Client: %w", err)
|
return fmt.Errorf("error attempting to close UDP Client: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/onyx-and-iris/vbantxt"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/onyx-and-iris/vbantxt"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed testdata/vm.txt
|
//go:embed testdata/vm.txt
|
||||||
@@ -28,14 +30,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(os.Getenv("VBANTXT_HOST"), 6980, os.Getenv("VBANTXT_STREAMNAME"))
|
||||||
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(os.Getenv("VBANTXT_HOST"), 6990, os.Getenv("VBANTXT_STREAMNAME"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
run(t, client, matrix)
|
run(t, client, matrix)
|
||||||
|
|||||||
Reference in New Issue
Block a user