From 21dc5fa6c6c843fcf263b6483d21bc4b284aad1c Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Sat, 3 Feb 2024 04:24:22 -0500 Subject: Form support for transport Ad-Hoc commands with arguments --- telegram/commands.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'telegram') diff --git a/telegram/commands.go b/telegram/commands.go index 47438e0..4dafdf5 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -107,9 +107,9 @@ var transportConfigurationOptions = map[string]configurationOption{ } type command struct { - requiredArgs int - arguments []string - description string + RequiredArgs int + Arguments []string + Description string } type configurationOption struct { arguments string @@ -138,14 +138,21 @@ func GetCommands(typ CommandType) map[string]command { return commandMap } +// GetCommand obtains one command +func GetCommand(typ CommandType, cmd string) (command, bool) { + commands := GetCommands(typ) + command, ok := commands[cmd] + return command, ok +} + // CommandToHelpString builds a text description of a command func CommandToHelpString(name string, cmd command) string { var str strings.Builder str.WriteString("/") str.WriteString(name) - for i, arg := range cmd.arguments { - optional := i >= cmd.requiredArgs + for i, arg := range cmd.Arguments { + optional := i >= cmd.RequiredArgs str.WriteString(" ") if optional { str.WriteString("[") @@ -156,7 +163,7 @@ func CommandToHelpString(name string, cmd command) string { } } str.WriteString(" — ") - str.WriteString(cmd.description) + str.WriteString(cmd.Description) return str.String() } @@ -267,7 +274,7 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) string if !ok { return "Unknown command" } - if len(args) < command.requiredArgs { + if len(args) < command.RequiredArgs { return notEnoughArguments } -- cgit v1.2.3