Skip to content

Commit 744e14e

Browse files
authored
Merge pull request #13 from hilli/info-subcommand
Add info subscommand
2 parents 0f9f39a + 9053c13 commit 744e14e

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

cmd/kefw2/cmd/info.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
Copyright © 2023-2025 Jens Hilligsøe
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.
21+
*/
22+
package cmd
23+
24+
import (
25+
"os"
26+
27+
"github.com/spf13/cobra"
28+
)
29+
30+
// infoCmd represents the info command
31+
var infoCmd = &cobra.Command{
32+
Use: "info",
33+
Short: "Display detailed information about the speaker",
34+
Long: `Display detailed information about the speaker including software version, IP address, and other available information.`,
35+
Args: cobra.ExactArgs(0),
36+
Run: func(cmd *cobra.Command, args []string) {
37+
// Update speaker info to ensure we have the latest data
38+
err := currentSpeaker.UpdateInfo()
39+
if err != nil {
40+
errorPrinter.Printf("Error updating speaker information: %s\n", err.Error())
41+
os.Exit(1)
42+
}
43+
44+
// Display speaker information
45+
headerPrinter.Print("Speaker Name: ")
46+
contentPrinter.Println(currentSpeaker.Name)
47+
48+
headerPrinter.Print("Model: ")
49+
contentPrinter.Println(currentSpeaker.Model)
50+
51+
headerPrinter.Print("Firmware Version: ")
52+
contentPrinter.Println(currentSpeaker.FirmwareVersion)
53+
54+
headerPrinter.Print("IP Address: ")
55+
contentPrinter.Println(currentSpeaker.IPAddress)
56+
57+
headerPrinter.Print("MAC Address: ")
58+
contentPrinter.Println(currentSpeaker.MacAddress)
59+
60+
headerPrinter.Print("Maximum Volume: ")
61+
contentPrinter.Printf("%d\n", currentSpeaker.MaxVolume)
62+
63+
// Get network operation mode
64+
networkMode, err := currentSpeaker.NetworkOperationMode()
65+
if err == nil {
66+
headerPrinter.Print("Network Mode: ")
67+
contentPrinter.Println(networkMode)
68+
}
69+
70+
// Get speaker power state
71+
speakerState, err := currentSpeaker.SpeakerState()
72+
if err == nil {
73+
headerPrinter.Print("Speaker State: ")
74+
contentPrinter.Println(speakerState)
75+
}
76+
77+
// Get current source
78+
source, err := currentSpeaker.Source()
79+
if err == nil {
80+
headerPrinter.Print("Current Source: ")
81+
contentPrinter.Println(source)
82+
}
83+
84+
// Get mute status
85+
muted, err := currentSpeaker.IsMuted()
86+
if err == nil {
87+
headerPrinter.Print("Muted: ")
88+
contentPrinter.Println(muted)
89+
}
90+
91+
// Get current volume
92+
volume, err := currentSpeaker.GetVolume()
93+
if err == nil {
94+
headerPrinter.Print("Current Volume: ")
95+
contentPrinter.Printf("%d\n", volume)
96+
}
97+
},
98+
}
99+
100+
func init() {
101+
rootCmd.AddCommand(infoCmd)
102+
}

cmd/kefw2/cmd/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
// volumeCmd represents the volume command
3636
var statusCmd = &cobra.Command{
3737
Use: "status",
38-
Aliases: []string{"info", "state", "st"},
38+
Aliases: []string{"state", "st"},
3939
Short: "Status of the speakers",
4040
Long: `Status of the speakers`,
4141
Args: cobra.ExactArgs(0),

0 commit comments

Comments
 (0)