Files
Bose-SoundTouch/cmd/soundtouch-cli/cmd_network.go
T
Tobias Gesellchen 62a67818d2 Fix golangci-lint issues: resolve range copy, naming, and whitespace violations
- Fix range copy issues in cmd_network.go (use indexing instead of copying 168-byte structs)
- Rename DiscoveryService to Service to avoid package name stuttering
- Update all references to use new Service constructor names
- Apply automatic whitespace fixes using golangci-lint --fix
- Reduce linting issues from 32 to 7 (only cyclomatic complexity remains)

Remaining issues are architectural complexity violations that require manual refactoring.
2026-01-10 00:02:59 +01:00

129 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 := range interfaces {
iface := &interfaces[i]
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 i := range activeInterfaces {
iface := &activeInterfaces[i]
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
}