aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-10-16 11:42:15 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-28 19:24:46 +0200
commit9a4518476d8c8f28340c6b44cd808e6d58fbeb98 (patch)
tree7187d819b77df909980b91cf0eebf6b033316dfe /commands
parent803a10d4fabbd30533721db2f5efaefbccd88cdd (diff)
downloadaerc-9a4518476d8c8f28340c6b44cd808e6d58fbeb98.tar.gz
commands: remove command set execute api
Do not expose the execution of a command via its command set. Instead, require a single command object to be resolved in order to execute it. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'commands')
-rw-r--r--commands/commands.go14
1 files changed, 5 insertions, 9 deletions
diff --git a/commands/commands.go b/commands/commands.go
index 1c303484..57f2e6dc 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -111,17 +111,13 @@ func templateData(
return data.Data()
}
-func (cmds *Commands) ExecuteCommand(cmdline string) error {
+func ExecuteCommand(cmd Command, cmdline string) error {
args := opt.LexArgs(cmdline)
- name, err := args.ArgSafe(0)
- if err != nil {
- return errors.New("Expected a command after template evaluation.")
- }
- if cmd, ok := cmds.dict()[name]; ok {
- log.Tracef("executing command %s", args.String())
- return cmd.Execute(args.Args())
+ if args.Count() == 0 {
+ return errors.New("No arguments")
}
- return NoSuchCommand(name)
+ log.Tracef("executing command %s", args.String())
+ return cmd.Execute(args.Args())
}
// expand template expressions