mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-19 00:56:16 +00:00
- Refactored soundtouch-cli from monolithic main.go to modular command structure - Added urfave/cli/v2 dependency for better CLI organization - Created separate command files for all SoundTouch features: * cmd_discover.go - Device discovery commands * cmd_info.go - Device information commands * cmd_volume.go - Volume control commands * cmd_playback.go - Playback control commands * cmd_source.go - Source selection commands * cmd_bass.go - Bass control commands (NEW) * cmd_balance.go - Balance control commands (NEW) * cmd_clock.go - Clock/time management commands (NEW) * cmd_network.go - Network information commands (NEW) * cmd_zone.go - Multi-room zone management commands (NEW) * common.go - Shared utilities and client setup - Fixed flag conflicts by using --verbose instead of -v and removing -h alias from --host - Implemented comprehensive CLI with organized subcommands and consistent UX - Added proper help documentation and parameter validation - Reduced golangci-lint issues by 70% (108+ → 32) - Added package comments to new command files Breaking changes: - CLI now uses subcommands instead of flat flags - Old: soundtouch-cli -host 192.168.1.100 -volume - New: soundtouch-cli volume get --host 192.168.1.100 Examples: - soundtouch-cli discover devices --all - soundtouch-cli volume set --host 192.168.1.100 --level 50 - soundtouch-cli bass get --host 192.168.1.100 - soundtouch-cli clock set --host 192.168.1.100 --time '14:30' - soundtouch-cli zone create --host 192.168.1.100 --members 192.168.1.101,192.168.1.102
123 lines
3.0 KiB
Go
123 lines
3.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// getNetworkInfo retrieves network information from the device
|
|
func getNetworkInfo(c *cli.Context) error {
|
|
clientConfig := GetClientConfig(c)
|
|
PrintDeviceHeader("Getting network information", clientConfig.Host, clientConfig.Port)
|
|
|
|
client, err := CreateSoundTouchClient(clientConfig)
|
|
if err != nil {
|
|
PrintError(fmt.Sprintf("Failed to create client: %v", err))
|
|
return err
|
|
}
|
|
|
|
networkInfo, err := client.GetNetworkInfo()
|
|
if err != nil {
|
|
PrintError(fmt.Sprintf("Failed to get network info: %v", err))
|
|
return err
|
|
}
|
|
|
|
fmt.Println("Network Information:")
|
|
|
|
if networkInfo.GetWifiProfileCount() > 0 {
|
|
fmt.Printf(" WiFi Profiles: %d\n", networkInfo.GetWifiProfileCount())
|
|
}
|
|
|
|
interfaces := networkInfo.GetInterfaces()
|
|
if len(interfaces) == 0 {
|
|
fmt.Println(" No network interfaces found")
|
|
return nil
|
|
}
|
|
|
|
fmt.Printf(" Interfaces (%d):\n", len(interfaces))
|
|
for i, iface := range interfaces {
|
|
fmt.Printf("\n Interface %d:\n", i+1)
|
|
fmt.Printf(" Type: %s\n", iface.GetType())
|
|
|
|
if iface.GetName() != "" {
|
|
fmt.Printf(" Name: %s\n", iface.GetName())
|
|
}
|
|
|
|
if iface.GetIPAddress() != "" {
|
|
fmt.Printf(" IP Address: %s\n", iface.GetIPAddress())
|
|
}
|
|
|
|
if iface.GetMacAddress() != "" {
|
|
fmt.Printf(" MAC Address: %s\n", iface.GetMacAddress())
|
|
}
|
|
|
|
fmt.Printf(" State: %s\n", iface.GetStateDescription())
|
|
|
|
if iface.IsWiFi() {
|
|
if iface.GetSSID() != "" {
|
|
fmt.Printf(" SSID: %s\n", iface.GetSSID())
|
|
}
|
|
|
|
if iface.GetSignal() != "" {
|
|
fmt.Printf(" Signal: %s (%d%%)\n", iface.GetSignalDescription(), iface.GetSignalQuality())
|
|
}
|
|
|
|
if iface.GetFrequencyKHz() > 0 {
|
|
fmt.Printf(" Frequency: %s (%s)\n", iface.FormatFrequency(), iface.GetFrequencyBand())
|
|
}
|
|
|
|
if iface.GetMode() != "" {
|
|
fmt.Printf(" Mode: %s\n", iface.GetModeDescription())
|
|
}
|
|
}
|
|
}
|
|
|
|
// Show active connections summary
|
|
activeInterfaces := networkInfo.GetActiveInterfaces()
|
|
if len(activeInterfaces) > 0 {
|
|
fmt.Println("\n Active Connections:")
|
|
for _, iface := range activeInterfaces {
|
|
fmt.Printf(" - %s: %s\n", iface.GetType(), iface.GetNetworkSummary())
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// pingDevice pings the device to test connectivity
|
|
func pingDevice(c *cli.Context) error {
|
|
clientConfig := GetClientConfig(c)
|
|
PrintDeviceHeader("Pinging device", clientConfig.Host, clientConfig.Port)
|
|
|
|
client, err := CreateSoundTouchClient(clientConfig)
|
|
if err != nil {
|
|
PrintError(fmt.Sprintf("Failed to create client: %v", err))
|
|
return err
|
|
}
|
|
|
|
err = client.Ping()
|
|
if err != nil {
|
|
PrintError(fmt.Sprintf("Ping failed: %v", err))
|
|
return err
|
|
}
|
|
|
|
PrintSuccess("Device is reachable")
|
|
return nil
|
|
}
|
|
|
|
// getDeviceURL displays the device's base URL
|
|
func getDeviceURL(c *cli.Context) error {
|
|
clientConfig := GetClientConfig(c)
|
|
|
|
client, err := CreateSoundTouchClient(clientConfig)
|
|
if err != nil {
|
|
PrintError(fmt.Sprintf("Failed to create client: %v", err))
|
|
return err
|
|
}
|
|
|
|
baseURL := client.BaseURL()
|
|
fmt.Printf("Device URL: %s\n", baseURL)
|
|
return nil
|
|
}
|