Skip to content

Commit 6be9c91

Browse files
committed
auto-coder: improve code documentation for command execution and utilities
- Add package-level documentation for command execution capabilities - Add comments explaining the purpose of supportCommands map - Improve documentation for getSupportedCommands function - Add detailed description for isCommand function - Enhance Executor function documentation with more details - Add documentation for lengthLastWord and lengthFirstWord functions Signed-off-by: codiing-hui <wecoding@yeah.net>
1 parent 7ad7d6e commit 6be9c91

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

internal/ui/coders/commands.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Package coders provides command execution capabilities for the AI terminal.
2+
// It handles commands like adding/removing files, asking questions, coding with AI,
3+
// committing changes, and more.
14
package coders
25

36
import (
@@ -20,8 +23,10 @@ import (
2023
"github.com/coding-hui/ai-terminal/internal/util/genericclioptions"
2124
)
2225

26+
// supportCommands maps command names to their handler functions
2327
var supportCommands = map[string]func(context.Context, ...string) error{}
2428

29+
// getSupportedCommands returns a list of all supported command names
2530
func getSupportedCommands() []string {
2631
commands := make([]string, 0, len(supportCommands))
2732
for cmd := range supportCommands {
@@ -56,12 +61,14 @@ func (c *CommandExecutor) registryCmds() {
5661
supportCommands["diff"] = c.diff
5762
}
5863

64+
// isCommand checks if the input string is a command (starts with ! or /)
5965
func (c *CommandExecutor) isCommand(input string) bool {
6066
input = strings.TrimSpace(input)
6167
return strings.HasPrefix(input, "!") || strings.HasPrefix(input, "/")
6268
}
6369

64-
// Executor Execute the command
70+
// Executor handles command execution. It parses the input, validates the command,
71+
// and executes the corresponding handler function.
6572
func (c *CommandExecutor) Executor(input string) {
6673
input = strings.TrimSpace(input)
6774
if input == "" {
@@ -347,7 +354,7 @@ func (c *CommandExecutor) diff(ctx context.Context, _ ...string) error {
347354
// Split and highlight diff lines
348355
lines := strings.Split(diffOutput, "\n")
349356
var highlightedLines []string
350-
357+
351358
for _, line := range lines {
352359
switch {
353360
case strings.HasPrefix(line, "+"):

internal/ui/console/utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package console
22

3+
// lengthLastWord calculates the length of the last word in a string.
4+
// A word is defined as a sequence of non-space characters.
5+
// Returns 0 if the string contains no words.
36
func lengthLastWord(str string) int {
47
metLastWord := false
58
metFirstChar := false
@@ -22,6 +25,9 @@ func lengthLastWord(str string) int {
2225
return 0 // no word in this string
2326
}
2427

28+
// lengthFirstWord calculates the length of the first word in a string.
29+
// A word is defined as a sequence of non-space characters.
30+
// Returns 0 if the string contains no words.
2531
func lengthFirstWord(str string) int {
2632
metFirstWord := false
2733
metLastChar := false

0 commit comments

Comments
 (0)