aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msg
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-12-04 23:39:49 +0100
committerRobin Jarry <robin@jarry.cc>2024-01-20 21:56:25 +0100
commit159fb38daf5336758abc425447cf2c2ed51de59a (patch)
treee7be3bea878b12e441332f89d7bc3c63db477c05 /commands/msg
parentd2817371867e94b621de4054b235d53312db8073 (diff)
downloadaerc-159fb38daf5336758abc425447cf2c2ed51de59a.tar.gz
commands: refactor registration
Register all commands with the same function and store them in the same map. Use bit flags to determine in which contexts each command should be available. Remove duplicate commands now that the same command can be exposed in multiple contexts. Refactor API to allow executing commands from other commands without import cycles. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Tested-by: Johannes Thyssen Tishman <johannes@thyssentishman.com>
Diffstat (limited to 'commands/msg')
-rw-r--r--commands/msg/archive.go6
-rw-r--r--commands/msg/copy.go6
-rw-r--r--commands/msg/delete.go7
-rw-r--r--commands/msg/envelope.go7
-rw-r--r--commands/msg/fold.go7
-rw-r--r--commands/msg/forward.go6
-rw-r--r--commands/msg/invite.go7
-rw-r--r--commands/msg/mark.go8
-rw-r--r--commands/msg/modify-labels.go6
-rw-r--r--commands/msg/move.go6
-rw-r--r--commands/msg/msg.go14
-rw-r--r--commands/msg/pipe.go6
-rw-r--r--commands/msg/read.go6
-rw-r--r--commands/msg/recall.go7
-rw-r--r--commands/msg/reply.go6
-rw-r--r--commands/msg/toggle-thread-context.go7
-rw-r--r--commands/msg/toggle-threads.go7
-rw-r--r--commands/msg/unsubscribe.go7
18 files changed, 95 insertions, 31 deletions
diff --git a/commands/msg/archive.go b/commands/msg/archive.go
index a46cc986..13f53290 100644
--- a/commands/msg/archive.go
+++ b/commands/msg/archive.go
@@ -35,7 +35,11 @@ func (a *Archive) ParseArchiveType(arg string) error {
}
func init() {
- register(Archive{})
+ commands.Register(Archive{})
+}
+
+func (Archive) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (Archive) Aliases() []string {
diff --git a/commands/msg/copy.go b/commands/msg/copy.go
index f91d885b..3620238a 100644
--- a/commands/msg/copy.go
+++ b/commands/msg/copy.go
@@ -15,7 +15,11 @@ type Copy struct {
}
func init() {
- register(Copy{})
+ commands.Register(Copy{})
+}
+
+func (Copy) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (Copy) Aliases() []string {
diff --git a/commands/msg/delete.go b/commands/msg/delete.go
index 869c6888..19f44b43 100644
--- a/commands/msg/delete.go
+++ b/commands/msg/delete.go
@@ -5,6 +5,7 @@ import (
"time"
"git.sr.ht/~rjarry/aerc/app"
+ "git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/ui"
@@ -15,7 +16,11 @@ import (
type Delete struct{}
func init() {
- register(Delete{})
+ commands.Register(Delete{})
+}
+
+func (Delete) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (Delete) Aliases() []string {
diff --git a/commands/msg/envelope.go b/commands/msg/envelope.go
index 62a266b0..24867fc1 100644
--- a/commands/msg/envelope.go
+++ b/commands/msg/envelope.go
@@ -6,6 +6,7 @@ import (
"strings"
"git.sr.ht/~rjarry/aerc/app"
+ "git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/lib/format"
"git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
@@ -18,7 +19,11 @@ type Envelope struct {
}
func init() {
- register(Envelope{})
+ commands.Register(Envelope{})
+}
+
+func (Envelope) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (Envelope) Aliases() []string {
diff --git a/commands/msg/fold.go b/commands/msg/fold.go
index e8eb7741..057d454e 100644
--- a/commands/msg/fold.go
+++ b/commands/msg/fold.go
@@ -3,6 +3,7 @@ package msg
import (
"errors"
+ "git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/lib/ui"
)
@@ -12,7 +13,11 @@ type Fold struct {
}
func init() {
- register(Fold{})
+ commands.Register(Fold{})
+}
+
+func (Fold) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (Fold) Aliases() []string {
diff --git a/commands/msg/forward.go b/commands/msg/forward.go
index 20e945c1..093ca2e2 100644
--- a/commands/msg/forward.go
+++ b/commands/msg/forward.go
@@ -33,7 +33,11 @@ type forward struct {
}
func init() {
- register(forward{})
+ commands.Register(forward{})
+}
+
+func (forward) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (forward) Aliases() []string {
diff --git a/commands/msg/invite.go b/commands/msg/invite.go
index 12bea93e..862af23c 100644
--- a/commands/msg/invite.go
+++ b/commands/msg/invite.go
@@ -6,6 +6,7 @@ import (
"io"
"git.sr.ht/~rjarry/aerc/app"
+ "git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/calendar"
@@ -21,7 +22,11 @@ type invite struct {
}
func init() {
- register(invite{})
+ commands.Register(invite{})
+}
+
+func (invite) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (invite) Aliases() []string {
diff --git a/commands/msg/mark.go b/commands/msg/mark.go
index 9547548f..f86c3413 100644
--- a/commands/msg/mark.go
+++ b/commands/msg/mark.go
@@ -2,6 +2,8 @@ package msg
import (
"fmt"
+
+ "git.sr.ht/~rjarry/aerc/commands"
)
type Mark struct {
@@ -13,7 +15,11 @@ type Mark struct {
}
func init() {
- register(Mark{})
+ commands.Register(Mark{})
+}
+
+func (Mark) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (Mark) Aliases() []string {
diff --git a/commands/msg/modify-labels.go b/commands/msg/modify-labels.go
index 8cc72f2a..e2637805 100644
--- a/commands/msg/modify-labels.go
+++ b/commands/msg/modify-labels.go
@@ -13,7 +13,11 @@ type ModifyLabels struct {
}
func init() {
- register(ModifyLabels{})
+ commands.Register(ModifyLabels{})
+}
+
+func (ModifyLabels) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (ModifyLabels) Aliases() []string {
diff --git a/commands/msg/move.go b/commands/msg/move.go
index 4eac1c14..000e2b2a 100644
--- a/commands/msg/move.go
+++ b/commands/msg/move.go
@@ -19,7 +19,11 @@ type Move struct {
}
func init() {
- register(Move{})
+ commands.Register(Move{})
+}
+
+func (Move) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (Move) Aliases() []string {
diff --git a/commands/msg/msg.go b/commands/msg/msg.go
deleted file mode 100644
index 65a40562..00000000
--- a/commands/msg/msg.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package msg
-
-import (
- "git.sr.ht/~rjarry/aerc/commands"
-)
-
-var MessageCommands *commands.Commands
-
-func register(cmd commands.Command) {
- if MessageCommands == nil {
- MessageCommands = commands.NewCommands()
- }
- MessageCommands.Register(cmd)
-}
diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go
index ee5cd965..8b47c418 100644
--- a/commands/msg/pipe.go
+++ b/commands/msg/pipe.go
@@ -25,7 +25,11 @@ type Pipe struct {
}
func init() {
- register(Pipe{})
+ commands.Register(Pipe{})
+}
+
+func (Pipe) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (Pipe) Aliases() []string {
diff --git a/commands/msg/read.go b/commands/msg/read.go
index e682a156..b487d8a8 100644
--- a/commands/msg/read.go
+++ b/commands/msg/read.go
@@ -19,7 +19,11 @@ type FlagMsg struct {
}
func init() {
- register(FlagMsg{})
+ commands.Register(FlagMsg{})
+}
+
+func (FlagMsg) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (FlagMsg) Aliases() []string {
diff --git a/commands/msg/recall.go b/commands/msg/recall.go
index a676010a..059fe558 100644
--- a/commands/msg/recall.go
+++ b/commands/msg/recall.go
@@ -11,6 +11,7 @@ import (
"github.com/pkg/errors"
"git.sr.ht/~rjarry/aerc/app"
+ "git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/log"
@@ -24,7 +25,11 @@ type Recall struct {
}
func init() {
- register(Recall{})
+ commands.Register(Recall{})
+}
+
+func (Recall) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (Recall) Aliases() []string {
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 333b3e3a..04c2eba5 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -34,7 +34,11 @@ type reply struct {
}
func init() {
- register(reply{})
+ commands.Register(reply{})
+}
+
+func (reply) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (reply) Aliases() []string {
diff --git a/commands/msg/toggle-thread-context.go b/commands/msg/toggle-thread-context.go
index 4b87eaa8..dfae3a22 100644
--- a/commands/msg/toggle-thread-context.go
+++ b/commands/msg/toggle-thread-context.go
@@ -1,13 +1,18 @@
package msg
import (
+ "git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/lib/ui"
)
type ToggleThreadContext struct{}
func init() {
- register(ToggleThreadContext{})
+ commands.Register(ToggleThreadContext{})
+}
+
+func (ToggleThreadContext) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (ToggleThreadContext) Aliases() []string {
diff --git a/commands/msg/toggle-threads.go b/commands/msg/toggle-threads.go
index d2933bba..21accc2c 100644
--- a/commands/msg/toggle-threads.go
+++ b/commands/msg/toggle-threads.go
@@ -1,6 +1,7 @@
package msg
import (
+ "git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/lib/state"
"git.sr.ht/~rjarry/aerc/lib/ui"
)
@@ -8,7 +9,11 @@ import (
type ToggleThreads struct{}
func init() {
- register(ToggleThreads{})
+ commands.Register(ToggleThreads{})
+}
+
+func (ToggleThreads) Context() commands.CommandContext {
+ return commands.MESSAGE
}
func (ToggleThreads) Aliases() []string {
diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go
index c6a0b23f..7ba497b4 100644
--- a/commands/msg/unsubscribe.go
+++ b/commands/msg/unsubscribe.go
@@ -9,6 +9,7 @@ import (
"time"
"git.sr.ht/~rjarry/aerc/app"
+ "git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/log"
@@ -23,7 +24,11 @@ type Unsubscribe struct {
}
func init() {
- register(Unsubscribe{})
+ commands.Register(Unsubscribe{})
+}
+
+func (Unsubscribe) Context() commands.CommandContext {
+ return commands.MESSAGE
}
// Aliases returns a list of aliases for the :unsubscribe command