Skip to content

Commit 18ee5cb

Browse files
committed
refactor: use distinct constants for CLI subcommand names
- Replaced hardcoded strings with specific constants to improve maintainability. - Split shared command values (e.g., "add") into domain-specific constants (e.g., UsersAddCmdName, GroupsAddCmdName) to better reflect the logical context, even where the underlying string values are identical. - No changes to existing functionality; the CLI interface remains unchanged.
1 parent b99ce04 commit 18ee5cb

18 files changed

Lines changed: 42 additions & 30 deletions

‎cli/cmd/autologin.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func loginRequired(name string) bool {
12-
loginRequiredCommands := []string{StatusCmdUse, SetStateCmdUse, AddCmdUse, InheritCmdUse, RemoveCmdUse}
12+
loginRequiredCommands := []string{StatusCmdName, SetStateCmdName, PortsAddCmdName, UsersAddCmdName, InheritCmdName, PortsRemoveCmdName, UsersRemoveCmdName}
1313

1414
for _, i := range loginRequiredCommands {
1515
if name == i {

‎cli/cmd/consts.go‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,28 @@ const (
2424
ArgMqttDeviceNameName = "mqttDeviceName"
2525
ArgMqttTelePeriodName = "mqttTelePeriod"
2626
ArgMqttTelePeriodFastName = "mqttTelePeriodFast"
27-
UsersCmdUse = "users"
28-
StatusCmdUse = "status"
29-
SetStateCmdUse = "set-state"
30-
GroupsCmdName = "groups"
31-
LoginCmdName = "login"
32-
LogoutCmdName = "logout"
33-
PingCmdName = "ping"
3427
HomeAssistantCmdName = "ha"
3528
ArgDoorStatusSupported = "doorStatusSupported"
3629
ArgDevicePortsName = "devicePorts"
3730
PortsCmdName = "ports"
38-
AddCmdUse = "add"
39-
InheritCmdUse = "inherit"
40-
RemoveCmdUse = "remove"
31+
PortsAddCmdName = "add"
32+
UsersAddCmdName = "add"
33+
InheritCmdName = "inherit"
34+
PortsRemoveCmdName = "remove"
35+
UsersRemoveCmdName = "remove"
36+
GroupsListCmdName = "list"
37+
UsersListCmdName = "list"
38+
PortsListCmdName = "ports-list"
39+
PasswordChangeCmdName = "password-change"
40+
DeleteCmdName = "delete"
41+
GroupsAddCmdName = "create"
42+
GetNameCmdName = "get-name"
43+
DiscoverCmdName = "discover"
44+
UsersCmdName = "users"
45+
StatusCmdName = "status"
46+
SetStateCmdName = "set-state"
47+
GroupsCmdName = "groups"
48+
LoginCmdName = "login"
49+
LogoutCmdName = "logout"
50+
PingCmdName = "ping"
4151
)

‎cli/cmd/discover.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package cmd
22

33
import (
4+
"context"
45
"halsecur/cli"
56
"halsecur/sdk"
6-
"context"
77
"os"
88
"time"
99

@@ -16,7 +16,7 @@ func init() {
1616
)
1717

1818
discoverCmd := &cobra.Command{
19-
Use: "discover",
19+
Use: DiscoverCmdName,
2020
Short: "Discover Hörmann BiSecur gateways on the local network",
2121
Long: ``,
2222
PreRunE: preRunFuncs,

‎cli/cmd/getName.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func init() {
1515
getNameCmd := &cobra.Command{
16-
Use: "get-name",
16+
Use: GetNameCmdName,
1717
Short: "Queries the name of the Hörmann BiSecur gateway",
1818
Long: ``,
1919
PreRunE: preRunFuncs,

‎cli/cmd/groupsAdd.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package cmd
22

33
import (
44
"halsecur/cli"
5+
56
"github.com/spf13/cobra"
67
)
78

89
var groupsCreateCmd = &cobra.Command{
9-
Use: "create",
10+
Use: GroupsAddCmdName,
1011
Short: "Create a new gateway group",
1112
Long: `Create a new gateway group`,
1213
PreRunE: preRunFuncs,

‎cli/cmd/groupsDelete.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package cmd
22

33
import (
44
"halsecur/cli"
5+
56
"github.com/spf13/cobra"
67
)
78

89
var groupsDeleteCmd = &cobra.Command{
9-
Use: "delete",
10+
Use: DeleteCmdName,
1011
Short: "Delete a gateway group",
1112
Long: `Delete a gateway group`,
1213
PreRunE: preRunFuncs,

‎cli/cmd/groupsList.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
var groupsListCmd = &cobra.Command{
15-
Use: "list",
15+
Use: GroupsListCmdName,
1616
Short: "List current gateway groups",
1717
Long: `List current gateway groups`,
1818
PreRunE: preRunFuncs,

‎cli/cmd/passwordChange.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func init() {
1717
)
1818

1919
passwordChangeCmd := &cobra.Command{
20-
Use: "password-change",
20+
Use: PasswordChangeCmdName,
2121
Short: "Change password of a gateway user",
2222
Long: `Change password of a gateway user`,
2323
Run: func(cmd *cobra.Command, args []string) {

‎cli/cmd/portsAdd.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
var portsAddCmd = &cobra.Command{
15-
Use: AddCmdUse,
15+
Use: PortsAddCmdName,
1616
Short: "Pair a new door by cloning a hand remote signal (ADD_PORT)",
1717
Long: `Pair a new door by cloning a hand remote's radio signal.
1818

‎cli/cmd/portsInherit.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
var portsInheritCmd = &cobra.Command{
15-
Use: InheritCmdUse,
15+
Use: InheritCmdName,
1616
Short: "Pair a new door by transmitting the gateway's radio code (INHERIT_PORT)",
1717
Long: `Pair a new door by having the gateway transmit its own radio code.
1818

0 commit comments

Comments
 (0)