refactor(cmd): clean up tool handling and Scanln usage
- Remove unnecessary comments and reset lines in chat.go for edit and scaffold tools. - Ignore return values from fmt.Scanln in edit.go and scaffold.go to handle potential errors. - Delete unused edit_helper_test.go file.
This commit is contained in:
parent
426288b356
commit
365f0c01ec
@ -184,18 +184,15 @@ func handleToolCall(reply string, history *[]map[string]string) {
|
|||||||
switch tc.Tool {
|
switch tc.Tool {
|
||||||
case "edit":
|
case "edit":
|
||||||
if tc.File != "" && tc.Instruction != "" {
|
if tc.File != "" && tc.Instruction != "" {
|
||||||
// Pass instruction directly to edit command
|
|
||||||
editInstruction = tc.Instruction
|
editInstruction = tc.Instruction
|
||||||
editCmd.SetArgs([]string{tc.File})
|
editCmd.SetArgs([]string{tc.File})
|
||||||
_ = editCmd.Execute()
|
_ = editCmd.Execute()
|
||||||
editInstruction = "" // reset
|
|
||||||
}
|
}
|
||||||
case "scaffold":
|
case "scaffold":
|
||||||
if tc.Path != "" && tc.Description != "" {
|
if tc.Path != "" && tc.Description != "" {
|
||||||
scaffoldDescription = tc.Description
|
scaffoldDescription = tc.Description
|
||||||
scaffoldCmd.SetArgs([]string{tc.Path})
|
scaffoldCmd.SetArgs([]string{tc.Path})
|
||||||
_ = scaffoldCmd.Execute()
|
_ = scaffoldCmd.Execute()
|
||||||
scaffoldDescription = ""
|
|
||||||
}
|
}
|
||||||
case "testgen":
|
case "testgen":
|
||||||
if tc.File != "" {
|
if tc.File != "" {
|
||||||
|
|||||||
@ -60,7 +60,7 @@ func runEdit(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
var confirm string
|
var confirm string
|
||||||
color.Yellow("Apply these changes to %s? (y/n): ", file)
|
color.Yellow("Apply these changes to %s? (y/n): ", file)
|
||||||
fmt.Scanln(&confirm)
|
_, _ = fmt.Scanln(&confirm)
|
||||||
|
|
||||||
if confirm != "y" && confirm != "Y" {
|
if confirm != "y" && confirm != "Y" {
|
||||||
color.Yellow("Aborted.")
|
color.Yellow("Aborted.")
|
||||||
|
|||||||
@ -1,53 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestRemoveLastModifiedComments(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
input string
|
|
||||||
expected string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "removes last modified comment",
|
|
||||||
input: "// Last modified: 2024-01-01\npackage main\n\nfunc main() {}",
|
|
||||||
expected: "package main\n\nfunc main() {}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "removes multiple last modified comments",
|
|
||||||
input: "// Last modified: 2024-01-01\npackage main\n// Last modified by: user\nfunc main() {}",
|
|
||||||
expected: "package main\nfunc main() {}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "preserves code without last modified",
|
|
||||||
input: "package main\n\nfunc main() {}",
|
|
||||||
expected: "package main\n\nfunc main() {}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "handles empty string",
|
|
||||||
input: "",
|
|
||||||
expected: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "preserves other comments",
|
|
||||||
input: "// This is a regular comment\npackage main\n// Last modified: 2024\n// Another comment\nfunc main() {}",
|
|
||||||
expected: "// This is a regular comment\npackage main\n// Another comment\nfunc main() {}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "handles line with only last modified",
|
|
||||||
input: "Last modified: 2024-01-01",
|
|
||||||
expected: "",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
result := removeLastModifiedComments(tt.input)
|
|
||||||
if result != tt.expected {
|
|
||||||
t.Errorf("removeLastModifiedComments() = %q, want %q", result, tt.expected)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -60,7 +60,7 @@ func runScaffold(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
var confirm string
|
var confirm string
|
||||||
color.Yellow("Create %s with this content? (y/n): ", path)
|
color.Yellow("Create %s with this content? (y/n): ", path)
|
||||||
fmt.Scanln(&confirm)
|
_, _ = fmt.Scanln(&confirm)
|
||||||
|
|
||||||
if confirm != "y" && confirm != "Y" {
|
if confirm != "y" && confirm != "Y" {
|
||||||
color.Yellow("Aborted.")
|
color.Yellow("Aborted.")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user