enable goconst linter

add package level constants for true/false str values
This commit is contained in:
onyx-and-iris 2026-02-15 14:58:59 +00:00
parent 23285e6e50
commit c8cfef858c
15 changed files with 57 additions and 47 deletions

View File

@ -6,7 +6,7 @@ run:
go: '1.24'
linters:
disable: [dupl, errcheck, goconst]
disable: [dupl, errcheck]
enable:
# Default enabled linters
- errcheck # Check for unchecked errors

View File

@ -36,7 +36,7 @@ func (cmd *BusMuteCmd) Run(ctx *context, bus *BusCmdGroup) error {
return nil
}
if err := ctx.Client.Bus.SetMute(bus.Index.Index, *cmd.State == "true"); err != nil {
if err := ctx.Client.Bus.SetMute(bus.Index.Index, *cmd.State == trueStr); err != nil {
return err
}
fmt.Fprintf(ctx.Out, "Bus %d mute state set to: %s\n", bus.Index.Index, *cmd.State)
@ -218,7 +218,7 @@ func (cmd *BusEqOnCmd) Run(ctx *context, bus *BusCmdGroup) error {
return nil
}
if err := ctx.Client.Bus.Eq.SetOn(bus.Index.Index, *cmd.State == "true"); err != nil {
if err := ctx.Client.Bus.Eq.SetOn(bus.Index.Index, *cmd.State == trueStr); err != nil {
return err
}
fmt.Fprintf(ctx.Out, "Bus %d EQ on state set to: %s\n", bus.Index.Index, *cmd.State)
@ -421,7 +421,7 @@ func (cmd *BusCompOnCmd) Run(ctx *context, bus *BusCmdGroup) error {
return nil
}
if err := ctx.Client.Bus.Comp.SetOn(bus.Index.Index, *cmd.State == "true"); err != nil {
if err := ctx.Client.Bus.Comp.SetOn(bus.Index.Index, *cmd.State == trueStr); err != nil {
return err
}
fmt.Fprintf(ctx.Out, "Bus %d compressor on state set to: %s\n", bus.Index.Index, *cmd.State)

View File

@ -15,6 +15,11 @@ import (
"github.com/onyx-and-iris/xair-cli/internal/xair"
)
const (
trueStr = "true"
falseStr = "false"
)
var version string // Version of the CLI, set at build time.
// VersionFlag is a custom flag type that prints the version and exits.

View File

@ -36,7 +36,7 @@ func (cmd *DCAMuteCmd) Run(ctx *context, dca *DCACmdGroup) error {
return nil
}
if err := ctx.Client.DCA.SetMute(dca.Index.Index, *cmd.State == "true"); err != nil {
if err := ctx.Client.DCA.SetMute(dca.Index.Index, *cmd.State == trueStr); err != nil {
return fmt.Errorf("failed to set DCA mute status: %w", err)
}
return nil

View File

@ -106,10 +106,10 @@ type HeadampPhantomCmd struct {
func (cmd *HeadampPhantomCmd) Validate() error {
if cmd.State != nil {
switch *cmd.State {
case "true", "on":
*cmd.State = "true"
case "false", "off":
*cmd.State = "false"
case trueStr, "on":
*cmd.State = trueStr
case falseStr, "off":
*cmd.State = falseStr
default:
return fmt.Errorf("invalid phantom power state: %s", *cmd.State)
}
@ -130,7 +130,7 @@ func (cmd *HeadampPhantomCmd) Run(ctx *context, headamp *HeadampCmdGroup) error
if err := ctx.Client.HeadAmp.SetPhantomPower(
headamp.Index.Index,
*cmd.State == "true",
*cmd.State == trueStr,
); err != nil {
return fmt.Errorf("failed to set headamp phantom power state: %w", err)
}

View File

@ -34,7 +34,7 @@ func (cmd *MainMuteCmd) Run(ctx *context) error {
return nil
}
if err := ctx.Client.Main.SetMute(*cmd.Mute == "true"); err != nil {
if err := ctx.Client.Main.SetMute(*cmd.Mute == trueStr); err != nil {
return fmt.Errorf("failed to set Main L/R mute state: %w", err)
}
fmt.Fprintf(ctx.Out, "Main L/R mute state set to: %s\n", *cmd.Mute)
@ -172,10 +172,10 @@ func (cmd *MainEqOnCmd) Run(ctx *context) error {
return nil
}
if err := ctx.Client.Main.Eq.SetOn(0, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.Main.Eq.SetOn(0, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set Main L/R EQ on/off state: %w", err)
}
fmt.Fprintf(ctx.Out, "Main L/R EQ on/off state set to: %t\n", *cmd.Enable == "true")
fmt.Fprintf(ctx.Out, "Main L/R EQ on/off state set to: %t\n", *cmd.Enable == trueStr)
return nil
}
@ -318,10 +318,10 @@ func (cmd *MainCompOnCmd) Run(ctx *context) error {
return nil
}
if err := ctx.Client.Main.Comp.SetOn(0, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.Main.Comp.SetOn(0, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set Main L/R compressor on/off state: %w", err)
}
fmt.Fprintf(ctx.Out, "Main L/R compressor on/off state set to: %t\n", *cmd.Enable == "true")
fmt.Fprintf(ctx.Out, "Main L/R compressor on/off state set to: %t\n", *cmd.Enable == trueStr)
return nil
}

View File

@ -33,7 +33,7 @@ func (cmd *MainMonoMuteCmd) Run(ctx *context) error {
return nil
}
if err := ctx.Client.MainMono.SetMute(*cmd.Mute == "true"); err != nil {
if err := ctx.Client.MainMono.SetMute(*cmd.Mute == trueStr); err != nil {
return fmt.Errorf("failed to set Main Mono mute state: %w", err)
}
fmt.Fprintf(ctx.Out, "Main Mono mute state set to: %s\n", *cmd.Mute)
@ -171,10 +171,10 @@ func (cmd *MainMonoEqOnCmd) Run(ctx *context) error {
return nil
}
if err := ctx.Client.MainMono.Eq.SetOn(0, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.MainMono.Eq.SetOn(0, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set Main Mono EQ on/off state: %w", err)
}
fmt.Fprintf(ctx.Out, "Main Mono EQ on/off state set to: %t\n", *cmd.Enable == "true")
fmt.Fprintf(ctx.Out, "Main Mono EQ on/off state set to: %t\n", *cmd.Enable == trueStr)
return nil
}
@ -337,10 +337,10 @@ func (cmd *MainMonoCompOnCmd) Run(ctx *context) error {
return nil
}
if err := ctx.Client.MainMono.Comp.SetOn(0, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.MainMono.Comp.SetOn(0, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set Main Mono compressor on/off state: %w", err)
}
fmt.Fprintf(ctx.Out, "Main Mono compressor on/off state set to: %t\n", *cmd.Enable == "true")
fmt.Fprintf(ctx.Out, "Main Mono compressor on/off state set to: %t\n", *cmd.Enable == trueStr)
return nil
}

View File

@ -43,7 +43,7 @@ func (cmd *MatrixMuteCmd) Run(ctx *context, matrix *MatrixCmdGroup) error {
return nil
}
if err := ctx.Client.Matrix.SetMute(matrix.Index.Index, *cmd.Mute == "true"); err != nil {
if err := ctx.Client.Matrix.SetMute(matrix.Index.Index, *cmd.Mute == trueStr); err != nil {
return fmt.Errorf("failed to set Matrix mute state: %w", err)
}
fmt.Fprintf(ctx.Out, "Matrix mute state set to: %s\n", *cmd.Mute)
@ -181,10 +181,10 @@ func (cmd *MatrixEqOnCmd) Run(ctx *context, matrix *MatrixCmdGroup) error {
return nil
}
if err := ctx.Client.Matrix.Eq.SetOn(matrix.Index.Index, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.Matrix.Eq.SetOn(matrix.Index.Index, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set Matrix EQ on/off state: %w", err)
}
fmt.Fprintf(ctx.Out, "Matrix EQ on/off state set to: %t\n", *cmd.Enable == "true")
fmt.Fprintf(ctx.Out, "Matrix EQ on/off state set to: %t\n", *cmd.Enable == trueStr)
return nil
}
@ -359,10 +359,10 @@ func (cmd *MatrixCompOnCmd) Run(ctx *context, matrix *MatrixCmdGroup) error {
return nil
}
if err := ctx.Client.Matrix.Comp.SetOn(matrix.Index.Index, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.Matrix.Comp.SetOn(matrix.Index.Index, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set Matrix compressor on/off state: %w", err)
}
fmt.Fprintf(ctx.Out, "Matrix compressor on/off state set to: %t\n", *cmd.Enable == "true")
fmt.Fprintf(ctx.Out, "Matrix compressor on/off state set to: %t\n", *cmd.Enable == trueStr)
return nil
}

View File

@ -38,7 +38,7 @@ func (cmd *StripMuteCmd) Run(ctx *context, strip *StripCmdGroup) error {
return nil
}
if err := ctx.Client.Strip.SetMute(strip.Index.Index, *cmd.State == "true"); err != nil {
if err := ctx.Client.Strip.SetMute(strip.Index.Index, *cmd.State == trueStr); err != nil {
return fmt.Errorf("failed to set mute state: %w", err)
}
fmt.Fprintf(ctx.Out, "Strip %d mute state set to: %s\n", strip.Index.Index, *cmd.State)
@ -242,7 +242,7 @@ func (cmd *StripGateOnCmd) Run(ctx *context, strip *StripCmdGroup) error {
return nil
}
if err := ctx.Client.Strip.Gate.SetOn(strip.Index.Index, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.Strip.Gate.SetOn(strip.Index.Index, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set gate state: %w", err)
}
fmt.Fprintf(ctx.Out, "Strip %d gate state set to: %s\n", strip.Index.Index, *cmd.Enable)
@ -442,7 +442,7 @@ func (cmd *StripEqOnCmd) Run(ctx *context, strip *StripCmdGroup) error {
return nil
}
if err := ctx.Client.Strip.Eq.SetOn(strip.Index.Index, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.Strip.Eq.SetOn(strip.Index.Index, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set EQ state: %w", err)
}
fmt.Fprintf(ctx.Out, "Strip %d EQ state set to: %s\n", strip.Index.Index, *cmd.Enable)
@ -646,7 +646,7 @@ func (cmd *StripCompOnCmd) Run(ctx *context, strip *StripCmdGroup) error {
return nil
}
if err := ctx.Client.Strip.Comp.SetOn(strip.Index.Index, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.Strip.Comp.SetOn(strip.Index.Index, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set compressor state: %w", err)
}
fmt.Fprintf(ctx.Out, "Strip %d compressor state set to: %s\n", strip.Index.Index, *cmd.Enable)

View File

@ -36,7 +36,7 @@ func (cmd *BusMuteCmd) Run(ctx *context, bus *BusCmdGroup) error {
return nil
}
if err := ctx.Client.Bus.SetMute(bus.Index.Index, *cmd.State == "true"); err != nil {
if err := ctx.Client.Bus.SetMute(bus.Index.Index, *cmd.State == trueStr); err != nil {
return err
}
fmt.Fprintf(ctx.Out, "Bus %d mute state set to: %s\n", bus.Index.Index, *cmd.State)
@ -218,7 +218,7 @@ func (cmd *BusEqOnCmd) Run(ctx *context, bus *BusCmdGroup) error {
return nil
}
if err := ctx.Client.Bus.Eq.SetOn(bus.Index.Index, *cmd.State == "true"); err != nil {
if err := ctx.Client.Bus.Eq.SetOn(bus.Index.Index, *cmd.State == trueStr); err != nil {
return err
}
fmt.Fprintf(ctx.Out, "Bus %d EQ on state set to: %s\n", bus.Index.Index, *cmd.State)
@ -421,7 +421,7 @@ func (cmd *BusCompOnCmd) Run(ctx *context, bus *BusCmdGroup) error {
return nil
}
if err := ctx.Client.Bus.Comp.SetOn(bus.Index.Index, *cmd.State == "true"); err != nil {
if err := ctx.Client.Bus.Comp.SetOn(bus.Index.Index, *cmd.State == trueStr); err != nil {
return err
}
fmt.Fprintf(ctx.Out, "Bus %d compressor on state set to: %s\n", bus.Index.Index, *cmd.State)

View File

@ -15,6 +15,11 @@ import (
"github.com/onyx-and-iris/xair-cli/internal/xair"
)
const (
trueStr = "true"
falseStr = "false"
)
var version string // Version of the CLI, set at build time.
// VersionFlag is a custom flag type that prints the version and exits.

View File

@ -37,7 +37,7 @@ func (cmd *DCAMuteCmd) Run(ctx *context, dca *DCACmdGroup) error {
return nil
}
if err := ctx.Client.DCA.SetMute(dca.Index.Index, *cmd.State == "true"); err != nil {
if err := ctx.Client.DCA.SetMute(dca.Index.Index, *cmd.State == trueStr); err != nil {
return fmt.Errorf("failed to set DCA mute status: %w", err)
}
return nil

View File

@ -106,10 +106,10 @@ type HeadampPhantomCmd struct {
func (cmd *HeadampPhantomCmd) Validate() error {
if cmd.State != nil {
switch *cmd.State {
case "true", "on":
*cmd.State = "true"
case "false", "off":
*cmd.State = "false"
case trueStr, "on":
*cmd.State = trueStr
case falseStr, "off":
*cmd.State = falseStr
default:
return fmt.Errorf("invalid phantom power state: %s", *cmd.State)
}
@ -130,7 +130,7 @@ func (cmd *HeadampPhantomCmd) Run(ctx *context, headamp *HeadampCmdGroup) error
if err := ctx.Client.HeadAmp.SetPhantomPower(
headamp.Index.Index,
*cmd.State == "true",
*cmd.State == trueStr,
); err != nil {
return fmt.Errorf("failed to set headamp phantom power state: %w", err)
}

View File

@ -34,7 +34,7 @@ func (cmd *MainMuteCmd) Run(ctx *context) error {
return nil
}
if err := ctx.Client.Main.SetMute(*cmd.Mute == "true"); err != nil {
if err := ctx.Client.Main.SetMute(*cmd.Mute == trueStr); err != nil {
return fmt.Errorf("failed to set Main L/R mute state: %w", err)
}
fmt.Fprintf(ctx.Out, "Main L/R mute state set to: %s\n", *cmd.Mute)
@ -172,10 +172,10 @@ func (cmd *MainEqOnCmd) Run(ctx *context) error {
return nil
}
if err := ctx.Client.Main.Eq.SetOn(0, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.Main.Eq.SetOn(0, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set Main L/R EQ on/off state: %w", err)
}
fmt.Fprintf(ctx.Out, "Main L/R EQ on/off state set to: %t\n", *cmd.Enable == "true")
fmt.Fprintf(ctx.Out, "Main L/R EQ on/off state set to: %t\n", *cmd.Enable == trueStr)
return nil
}
@ -318,10 +318,10 @@ func (cmd *MainCompOnCmd) Run(ctx *context) error {
return nil
}
if err := ctx.Client.Main.Comp.SetOn(0, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.Main.Comp.SetOn(0, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set Main L/R compressor on/off state: %w", err)
}
fmt.Fprintf(ctx.Out, "Main L/R compressor on/off state set to: %t\n", *cmd.Enable == "true")
fmt.Fprintf(ctx.Out, "Main L/R compressor on/off state set to: %t\n", *cmd.Enable == trueStr)
return nil
}

View File

@ -38,7 +38,7 @@ func (cmd *StripMuteCmd) Run(ctx *context, strip *StripCmdGroup) error {
return nil
}
if err := ctx.Client.Strip.SetMute(strip.Index.Index, *cmd.State == "true"); err != nil {
if err := ctx.Client.Strip.SetMute(strip.Index.Index, *cmd.State == trueStr); err != nil {
return fmt.Errorf("failed to set mute state: %w", err)
}
fmt.Fprintf(ctx.Out, "Strip %d mute state set to: %s\n", strip.Index.Index, *cmd.State)
@ -242,7 +242,7 @@ func (cmd *StripGateOnCmd) Run(ctx *context, strip *StripCmdGroup) error {
return nil
}
if err := ctx.Client.Strip.Gate.SetOn(strip.Index.Index, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.Strip.Gate.SetOn(strip.Index.Index, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set gate state: %w", err)
}
fmt.Fprintf(ctx.Out, "Strip %d gate state set to: %s\n", strip.Index.Index, *cmd.Enable)
@ -442,7 +442,7 @@ func (cmd *StripEqOnCmd) Run(ctx *context, strip *StripCmdGroup) error {
return nil
}
if err := ctx.Client.Strip.Eq.SetOn(strip.Index.Index, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.Strip.Eq.SetOn(strip.Index.Index, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set EQ state: %w", err)
}
fmt.Fprintf(ctx.Out, "Strip %d EQ state set to: %s\n", strip.Index.Index, *cmd.Enable)
@ -646,7 +646,7 @@ func (cmd *StripCompOnCmd) Run(ctx *context, strip *StripCmdGroup) error {
return nil
}
if err := ctx.Client.Strip.Comp.SetOn(strip.Index.Index, *cmd.Enable == "true"); err != nil {
if err := ctx.Client.Strip.Comp.SetOn(strip.Index.Index, *cmd.Enable == trueStr); err != nil {
return fmt.Errorf("failed to set compressor state: %w", err)
}
fmt.Fprintf(ctx.Out, "Strip %d compressor state set to: %s\n", strip.Index.Index, *cmd.Enable)