Skip to content

Commit

Permalink
Pass down device in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Dec 11, 2024
1 parent 5ede8a5 commit e5101e2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
9 changes: 6 additions & 3 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"errors"
"flag"

"github.com/Jacalz/hegelmote/device"
)

var (
Expand All @@ -16,6 +18,7 @@ type arguments struct {
ip string
port string
interactive bool
amplifier device.Device
}

func parseArguments() (arguments, error) {
Expand All @@ -24,12 +27,12 @@ func parseArguments() (arguments, error) {
// Flags for starting in interactive mode.
flag.BoolVar(&args.interactive, "i", false, "starts an interactive command terminal")
flag.BoolVar(&args.interactive, "interactive", false, "starts an interactive command terminal")

flag.UintVar(&args.amplifier, "device", 1, "sets the device to use for input mappings")
flag.Parse()

if len(flag.Args()) == 0 {
if flag.NArg() == 0 {
return arguments{}, errTooFewArgs
} else if len(flag.Args()) > 2 {
} else if flag.NArg() > 2 {
return arguments{}, errTooManyArgs
}

Expand Down
2 changes: 1 addition & 1 deletion device/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// Device defines the Hegel amplifier to target.
type Device uint8
type Device = uint

const (
Röst Device = iota
Expand Down
10 changes: 5 additions & 5 deletions interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

var errInvalidCommand = errors.New("invalid command format")

func runInteractiveMode(control *remote.Control) {
func runInteractiveMode(control *remote.Control, amplifier device.Device) {
input := bufio.NewScanner(os.Stdin)
input.Split(bufio.ScanLines)

Expand All @@ -28,7 +28,7 @@ func runInteractiveMode(control *remote.Control) {
case "volume":
handleVolumeCommand(commands[1:], control)
case "input", "source":
handleSourceCommand(commands[1:], control)
handleSourceCommand(commands[1:], control, amplifier)
case "reset":
handleResetCommand(commands[1:], control)
case "exit", "quit":
Expand Down Expand Up @@ -118,7 +118,7 @@ func handleVolumeCommand(subcommands []string, control *remote.Control) {
}
}

func handleSourceCommand(subcommands []string, control *remote.Control) {
func handleSourceCommand(subcommands []string, control *remote.Control, amplifier device.Device) {
switch subcommands[0] {
case "set":
if len(subcommands) == 1 {
Expand All @@ -130,7 +130,7 @@ func handleSourceCommand(subcommands []string, control *remote.Control) {
err = control.SetSourceNumber(uint(number))
} else {
input := strings.Join(subcommands[1:], " ")
err = control.SetSourceName(device.H95, input)
err = control.SetSourceName(amplifier, input)
}

if err != nil {
Expand All @@ -142,7 +142,7 @@ func handleSourceCommand(subcommands []string, control *remote.Control) {
exitWithError(err)
}

source, _ := device.NameFromNumber(device.H95, number)
source, _ := device.NameFromNumber(amplifier, number)
fmt.Println("Selected input:", number, "-", source)
}
}
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"os"

Expand All @@ -24,7 +25,9 @@ func main() {
}

if args.interactive {
runInteractiveMode(command)
runInteractiveMode(command, args.amplifier)
return
}

flag.PrintDefaults()
}

0 comments on commit e5101e2

Please sign in to comment.