Documentation for controlling and preserving Bose SoundTouch devices
This document describes the automatic host:port parsing functionality added to the SoundTouch CLI, which allows users to specify both host and port in a single -host flag.
The SoundTouch CLI now supports parsing host and port combinations in the -host flag, making it more user-friendly and following common CLI patterns. Users can specify either just a host (using the default or -port flag) or a complete host:port combination.
# Specify host and port together
soundtouch-cli -host 192.168.1.100:8090 -info
soundtouch-cli -host 192.168.178.35:8090 -play
soundtouch-cli -host soundtouch.local:8090 -pause
# Traditional separate host and port flags
soundtouch-cli -host 192.168.1.100 -port 8090 -info
soundtouch-cli -host 192.168.178.35 -port 8090 -play
When both formats are used, the port specified in the host:port format takes precedence:
# Uses port 8090 from host:port, ignores -port 9999
soundtouch-cli -host 192.168.1.100:8090 -port 9999 -info
# Standard IPv4 with port
soundtouch-cli -host 192.168.1.100:8090 -info
# IPv4 without port (uses default 8090)
soundtouch-cli -host 192.168.1.100 -info
# Hostname with port
soundtouch-cli -host soundtouch.local:8090 -info
soundtouch-cli -host bose-kitchen:9000 -play
# Hostname without port (uses default)
soundtouch-cli -host soundtouch.local -info
# IPv6 with port (requires brackets)
soundtouch-cli -host [::1]:8090 -info
soundtouch-cli -host [2001:db8::1]:8090 -play
# IPv6 without port
soundtouch-cli -host ::1 -info
The parseHostPort() function handles the parsing logic:
func parseHostPort(hostPort string, defaultPort int) (string, int)
net.SplitHostPort()The parser is designed to be forgiving and always return usable values:
net.SplitHostPort() error handlingComprehensive test coverage in cmd/soundtouch-cli/main_test.go:
Tested with real SoundTouch devices:
host:port is more intuitive than separate flags# Discover devices to find host:port
$ soundtouch-cli -discover
Found SoundTouch devices:
My SoundTouch Device (192.168.1.10:8090) - SoundTouch 20
# Use discovered host:port directly
$ soundtouch-cli -host 192.168.1.10:8090 -play
# Standard SoundTouch port
soundtouch-cli -host 192.168.1.100:8090 -info
# Custom port (if device configured differently)
soundtouch-cli -host 192.168.1.100:9000 -info
# Default port fallback
soundtouch-cli -host 192.168.1.100 -info # Uses 8090
# Invalid port - uses default 8090
soundtouch-cli -host 192.168.1.100:invalid -info
# Out of range port - uses default 8090
soundtouch-cli -host 192.168.1.100:99999 -info
# Malformed input - treats as hostname
soundtouch-cli -host "malformed::input" -info
The help text has been updated to reflect the new functionality:
Options:
-host <ip> SoundTouch device IP address (or host:port)
-port <port> SoundTouch device port (default: 8090)
Examples:
soundtouch-cli -host 192.168.1.100 -info
soundtouch-cli -host 192.168.1.100:8090 -info
soundtouch-cli -host 192.168.1.100:8090 -pause
soundtouch-cli -host 192.168.1.100:8090 -preset 1
// parseHostPort splits a host:port string into separate host and port components
// If no port is specified, returns the original host and the provided default port
func parseHostPort(hostPort string, defaultPort int) (string, int)
net.SplitHostPort() for robust parsingThe parsed values are used throughout the CLI:
Potential improvements for the future:
http://192.168.1.100:8090SOUNDTOUCH_HOST with host:port formatcmd/soundtouch-cli/main.go (parseHostPort function)cmd/soundtouch-cli/main_test.gonet.SplitHostPort() for parsing logic