From 365f0c01ec4d0cac51c325eeab5bf26e16850a6d Mon Sep 17 00:00:00 2001 From: Gregory Gauthier Date: Wed, 4 Mar 2026 14:18:23 +0000 Subject: [PATCH] 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. --- cmd/chat.go | 3 --- cmd/edit.go | 2 +- cmd/edit_helper_test.go | 53 ----------------------------------------- cmd/scaffold.go | 2 +- 4 files changed, 2 insertions(+), 58 deletions(-) delete mode 100644 cmd/edit_helper_test.go diff --git a/cmd/chat.go b/cmd/chat.go index 0226766..64817e4 100644 --- a/cmd/chat.go +++ b/cmd/chat.go @@ -184,18 +184,15 @@ func handleToolCall(reply string, history *[]map[string]string) { switch tc.Tool { case "edit": if tc.File != "" && tc.Instruction != "" { - // Pass instruction directly to edit command editInstruction = tc.Instruction editCmd.SetArgs([]string{tc.File}) _ = editCmd.Execute() - editInstruction = "" // reset } case "scaffold": if tc.Path != "" && tc.Description != "" { scaffoldDescription = tc.Description scaffoldCmd.SetArgs([]string{tc.Path}) _ = scaffoldCmd.Execute() - scaffoldDescription = "" } case "testgen": if tc.File != "" { diff --git a/cmd/edit.go b/cmd/edit.go index 90a9dd9..5983693 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -60,7 +60,7 @@ func runEdit(cmd *cobra.Command, args []string) { var confirm string color.Yellow("Apply these changes to %s? (y/n): ", file) - fmt.Scanln(&confirm) + _, _ = fmt.Scanln(&confirm) if confirm != "y" && confirm != "Y" { color.Yellow("Aborted.") diff --git a/cmd/edit_helper_test.go b/cmd/edit_helper_test.go deleted file mode 100644 index 4f19aa0..0000000 --- a/cmd/edit_helper_test.go +++ /dev/null @@ -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) - } - }) - } -} diff --git a/cmd/scaffold.go b/cmd/scaffold.go index 921ade8..2b9025c 100644 --- a/cmd/scaffold.go +++ b/cmd/scaffold.go @@ -60,7 +60,7 @@ func runScaffold(cmd *cobra.Command, args []string) { var confirm string color.Yellow("Create %s with this content? (y/n): ", path) - fmt.Scanln(&confirm) + _, _ = fmt.Scanln(&confirm) if confirm != "y" && confirm != "Y" { color.Yellow("Aborted.")