Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseSlashCommand ¶
func ParseSlashCommand(command string) (taskName string, params map[string]string, found bool, err error)
ParseSlashCommand parses a slash command string and extracts the task name and parameters. It searches for a slash command anywhere in the input string, not just at the beginning. The expected format is: /task-name arg1 "arg 2" arg3
The function will find the slash command even if it's embedded in other text. For example:
- "Please /fix-bug 123 today" -> taskName: "fix-bug", params: {"ARGUMENTS": "123 today", "1": "123", "2": "today"}, found: true
- "Some text /code-review" -> taskName: "code-review", params: {}, found: true
Arguments are parsed like Bash:
- Quoted arguments can contain spaces
- Both single and double quotes are supported
- Quotes are removed from the parsed arguments
- Arguments are extracted until end of line
Examples:
- "/fix-bug 123" -> taskName: "fix-bug", params: {"ARGUMENTS": "123", "1": "123"}, found: true
- "/code-review \"PR #42\" high" -> taskName: "code-review", params: {"ARGUMENTS": "\"PR #42\" high", "1": "PR #42", "2": "high"}, found: true
- "no command here" -> taskName: "", params: nil, found: false
Returns:
- taskName: the task name (without the leading slash)
- params: a map containing:
- "ARGUMENTS": the full argument string (with quotes preserved)
- "1", "2", "3", etc.: positional arguments (with quotes removed)
- found: true if a slash command was found, false otherwise
- err: an error if the command format is invalid (e.g., unclosed quotes)
Example ¶
package main
import (
"fmt"
"github.com/kitproj/coding-context-cli/pkg/slashcommand"
)
func main() {
// Parse a simple command without parameters
taskName, params, found, err := slashcommand.ParseSlashCommand("/fix-bug")
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
if found {
fmt.Printf("Task: %s, Params: %v\n", taskName, params)
}
// Parse a command with single argument
taskName, params, found, err = slashcommand.ParseSlashCommand("/fix-bug 123")
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
if found {
fmt.Printf("Task: %s, $1: %s\n", taskName, params["1"])
}
// Parse a command with multiple arguments
taskName, params, found, err = slashcommand.ParseSlashCommand(`/implement-feature "User Login" high`)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
if found {
fmt.Printf("Task: %s, $1: %s, $2: %s\n", taskName, params["1"], params["2"])
}
}
Output: Task: fix-bug, Params: map[] Task: fix-bug, $1: 123 Task: implement-feature, $1: User Login, $2: high
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.