refactor: replace all bare command string literals with named constants
All checks were successful
check / check (push) Successful in 2m15s

Extract cmdLusers, cmdMode, cmdMotd, cmdNames, cmdNotice, cmdPing, cmdPong
constants in internal/handlers/api.go. Add corresponding constants in
cmd/neoirc-cli/main.go and cmd/neoirc-cli/api/client.go. Replace every bare
IRC command string literal in switch cases and command dispatch code with the
named constant. Zero bare command strings remain in any dispatch path.
This commit is contained in:
2026-03-09 15:23:00 -07:00
parent a193831ed4
commit 5efb4b6949
3 changed files with 49 additions and 28 deletions

View File

@@ -16,6 +16,17 @@ const (
pollTimeout = 15
pollRetry = 2 * time.Second
timeFormat = "15:04"
cmdJoin = "JOIN"
cmdMotd = "MOTD"
cmdNick = "NICK"
cmdNotice = "NOTICE"
cmdPart = "PART"
cmdPrivmsg = "PRIVMSG"
cmdQuit = "QUIT"
cmdTopic = "TOPIC"
cmdWho = "WHO"
cmdWhois = "WHOIS"
)
// App holds the application state.
@@ -86,7 +97,7 @@ func (a *App) handleInput(text string) {
}
err := a.client.SendMessage(&api.Message{ //nolint:exhaustruct
Command: "PRIVMSG",
Command: cmdPrivmsg,
To: target,
Body: []string{text},
})
@@ -241,7 +252,7 @@ func (a *App) cmdNick(nick string) {
}
err := a.client.SendMessage(&api.Message{ //nolint:exhaustruct
Command: "NICK",
Command: cmdNick,
Body: []string{nick},
})
if err != nil {
@@ -376,7 +387,7 @@ func (a *App) cmdMsg(args string) {
}
err := a.client.SendMessage(&api.Message{ //nolint:exhaustruct
Command: "PRIVMSG",
Command: cmdPrivmsg,
To: target,
Body: []string{text},
})
@@ -434,7 +445,7 @@ func (a *App) cmdTopic(args string) {
if args == "" {
err := a.client.SendMessage(&api.Message{ //nolint:exhaustruct
Command: "TOPIC",
Command: cmdTopic,
To: target,
})
if err != nil {
@@ -447,7 +458,7 @@ func (a *App) cmdTopic(args string) {
}
err := a.client.SendMessage(&api.Message{ //nolint:exhaustruct
Command: "TOPIC",
Command: cmdTopic,
To: target,
Body: []string{args},
})
@@ -535,7 +546,7 @@ func (a *App) cmdMotd() {
}
err := a.client.SendMessage(
&api.Message{Command: "MOTD"}, //nolint:exhaustruct
&api.Message{Command: cmdMotd}, //nolint:exhaustruct
)
if err != nil {
a.ui.AddStatus(fmt.Sprintf(
@@ -572,7 +583,7 @@ func (a *App) cmdWho(args string) {
err := a.client.SendMessage(
&api.Message{ //nolint:exhaustruct
Command: "WHO", To: channel,
Command: cmdWho, To: channel,
},
)
if err != nil {
@@ -603,7 +614,7 @@ func (a *App) cmdWhois(args string) {
err := a.client.SendMessage(
&api.Message{ //nolint:exhaustruct
Command: "WHOIS", To: args,
Command: cmdWhois, To: args,
},
)
if err != nil {
@@ -653,7 +664,7 @@ func (a *App) cmdQuit() {
if a.connected && a.client != nil {
_ = a.client.SendMessage(
&api.Message{Command: "QUIT"}, //nolint:exhaustruct
&api.Message{Command: cmdQuit}, //nolint:exhaustruct
)
}
@@ -738,19 +749,19 @@ func (a *App) handleServerMessage(msg *api.Message) {
a.mu.Unlock()
switch msg.Command {
case "PRIVMSG":
case cmdPrivmsg:
a.handlePrivmsgEvent(msg, timestamp, myNick)
case "JOIN":
case cmdJoin:
a.handleJoinEvent(msg, timestamp)
case "PART":
case cmdPart:
a.handlePartEvent(msg, timestamp)
case "QUIT":
case cmdQuit:
a.handleQuitEvent(msg, timestamp)
case "NICK":
case cmdNick:
a.handleNickEvent(msg, timestamp, myNick)
case "NOTICE":
case cmdNotice:
a.handleNoticeEvent(msg, timestamp)
case "TOPIC":
case cmdTopic:
a.handleTopicEvent(msg, timestamp)
default:
a.handleDefaultEvent(msg, timestamp)