parseSlashCommandShorthand parses a string in the format "/command" and returns the command name. It returns an empty string if the input is not a valid slash command shorthand. It returns an error if the input starts with "/" but has an empty command name.
(input string)
| 13 | // It returns an empty string if the input is not a valid slash command shorthand. |
| 14 | // It returns an error if the input starts with "/" but has an empty command name. |
| 15 | func parseSlashCommandShorthand(input string) (commandName string, isSlashCommand bool, err error) { |
| 16 | // Check if it's a slash command shorthand (starts with /) |
| 17 | if !strings.HasPrefix(input, "/") { |
| 18 | return "", false, nil |
| 19 | } |
| 20 | |
| 21 | // Extract command name (remove leading /) |
| 22 | commandName = strings.TrimPrefix(input, "/") |
| 23 | if commandName == "" { |
| 24 | return "", true, errors.New("slash command shorthand cannot be empty after '/'") |
| 25 | } |
| 26 | |
| 27 | slashCommandParserLog.Printf("Parsed slash command shorthand: /%s -> command name: %s", input, commandName) |
| 28 | |
| 29 | return commandName, true, nil |
| 30 | } |
| 31 | |
| 32 | // expandSlashCommandShorthand takes a command name and returns a map that represents |
| 33 | // the expanded slash_command + workflow_dispatch configuration. |