Skip to content

Commit af78568

Browse files
committed
docs: optimize printing information
1 parent d0af80b commit af78568

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

cmd/sponge/commands/assistant/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func deleteGenFiles(files []string, assistantType string) {
512512
}
513513

514514
if len(doneFiles) > 0 {
515-
fmt.Printf("Clean up code files generated by [%s] assistant:\n", assistantType)
515+
fmt.Printf("Removed temporary files generated by AI Assistant (%s):\n", assistantType)
516516
for _, file := range doneFiles {
517517
fmt.Printf(" %s\n", color.HiGreenString(cutFilePath(file)))
518518
}

cmd/sponge/commands/assistant/generate.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ func (g *assistantGenerator) generateCode() error {
161161
}
162162
workerPool.Start()
163163

164-
fmt.Printf("\n[INFO] Detected %s files for code generation. Processing concurrently with %s AI assistants (%s).\n\n",
165-
color.HiCyanString(strconv.Itoa(fileCount)), color.HiCyanString(strconv.Itoa(g.maxAssistantNum)), g.asst.model)
164+
fmt.Printf("\n%s [INFO] Detected %s files for code generation. Processing concurrently with %s AI assistants (%s).\n\n",
165+
time.Now().Format(time.DateTime),
166+
color.HiCyanString(strconv.Itoa(fileCount)),
167+
color.HiCyanString(strconv.Itoa(g.maxAssistantNum)),
168+
g.asst.model)
166169

167170
jobID := 0
168171

@@ -235,7 +238,8 @@ func (g *assistantGenerator) generateCode() error {
235238
newFiles = append(newFiles, cutFilePath(newFile))
236239
outputFiles = append(outputFiles, newFile)
237240
}
238-
l := fmt.Sprintf("\n[SUCCESS] Job %s - File: [%s] | Functions: [%s] | Output: [%s] | Time: %s\n",
241+
l := fmt.Sprintf("\n%s [SUCCESS] Job %s - File: [%s] | Functions: [%s] | Output: [%s] | Time: %s\n",
242+
time.Now().Format(time.DateTime),
239243
color.HiCyanString(strconv.Itoa(reply.JobID)),
240244
color.HiCyanString(cutFilePath(reply.SrcFile)),
241245
color.HiCyanString(strings.Join(reply.Functions, ", ")),
@@ -271,7 +275,7 @@ func (g *assistantGenerator) generateCode() error {
271275
}
272276

273277
if len(outputFiles) > 0 {
274-
fmt.Println("Files Output by Successful Jobs:")
278+
fmt.Println("Output Files:")
275279
for _, file := range outputFiles {
276280
fmt.Printf(" • %s\n", color.HiGreenString(cutFilePath(file)))
277281
}
@@ -316,7 +320,8 @@ func (t *assistantTask) Execute(ctx context.Context) (interface{}, error) {
316320
return taskReply, nil
317321
}
318322

319-
fmt.Printf("[START] Job %s - File: [%s] | Functions: [%s]\n\n",
323+
fmt.Printf("%s [START] Job %s - File: [%s] | Functions: [%s]\n\n",
324+
time.Now().Format(time.DateTime),
320325
color.HiCyanString(strconv.Itoa(t.jobID)),
321326
color.HiCyanString(cutFilePath(t.file)),
322327
color.HiCyanString(strings.Join(t.funcNames, ", ")),

cmd/sponge/commands/assistant/merge.go

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path/filepath"
88
"strings"
9+
"time"
910

1011
"github.com/fatih/color"
1112
"github.com/spf13/cobra"
@@ -27,14 +28,15 @@ func MergeAssistantCode() *cobra.Command {
2728
Use: "merge",
2829
Short: "Merge AI assistant generated code into source Go file",
2930
Long: "Merge AI assistant generated code into source Go file.",
30-
Example: color.HiBlackString(` # Merge deepseek generated code into source Go file in specified directory
31+
Example: color.HiBlackString(` # Merge DeepSeek-generated code into Go source files under the specified directory
3132
sponge assistant merge --type=deepseek --dir=/path/to/directory
3233
33-
# Merge chatgpt generated code into source Go file in specified directory
34-
sponge assistant merge --type=chatgpt --dir=/path/to/directory
34+
# Merge ChatGPT-generated code into the specified Go source file
35+
sponge assistant merge --type=chatgpt --dir=/path/to/xxx.go
3536
36-
# Merge gemini generated code into source Go file in specified directory
37-
sponge assistant merge --type=gemini --dir=/path/to/directory`),
37+
# Merge Gemini-generated code into Go source files under the specified directory,
38+
# and remove assistant-generated code after the merge
39+
sponge assistant merge --type=gemini --dir=/path/to/directory --is-clean=true`),
3840
SilenceErrors: true,
3941
SilenceUsage: true,
4042
RunE: func(cmd *cobra.Command, args []string) error {
@@ -72,7 +74,8 @@ func MergeAssistantCode() *cobra.Command {
7274
var deleteFiles []string
7375
backupDir := getBackupDir()
7476
if len(mergeCodes) > 0 {
75-
fmt.Printf("Merged to Go files:\n")
77+
fmt.Printf("Merged Time: %s\n\n", time.Now().Format(time.DateTime))
78+
fmt.Printf("Merged Files:\n")
7679
for srcFile, code := range mergeCodes {
7780
backupFile(srcFile, backupDir)
7881
if err = os.WriteFile(srcFile, []byte(code), 0666); err != nil {
@@ -90,7 +93,7 @@ func MergeAssistantCode() *cobra.Command {
9093
}
9194

9295
if len(mergeCodes) > 0 {
93-
fmt.Printf("\n[Tip] You can view the pre-merge Go code files here:\n %s\n\n", backupDir)
96+
fmt.Printf("\n[Tip] Backed up Go files, you can restore the pre merge Go code from here:\n %s\n\n", backupDir)
9497
}
9598

9699
return nil
@@ -99,8 +102,8 @@ func MergeAssistantCode() *cobra.Command {
99102

100103
cmd.Flags().StringVarP(&assistantType, "type", "t", "", "assistant type, supported types: chatgpt, deepseek, gemini")
101104
_ = cmd.MarkFlagRequired("type")
102-
cmd.Flags().StringVarP(&dir, "dir", "d", ".", "input directory")
103-
cmd.Flags().StringSliceVarP(&files, "file", "f", nil, "specified Go files")
105+
cmd.Flags().StringVarP(&dir, "dir", "d", "", "go project directory")
106+
cmd.Flags().StringSliceVarP(&files, "file", "f", nil, "specified Go files or generated assistant code files")
104107
cmd.Flags().BoolVarP(&isClean, "is-clean", "c", false, "clean up assistant generated code after merge")
105108

106109
return cmd
@@ -116,8 +119,8 @@ type mergeParams struct {
116119
func (m *mergeParams) parseAssistantFiles() (map[string]string, error) {
117120
fileMap := make(map[string]string) // srcFile -> genFile
118121

119-
for _, genFile := range m.specifiedFiles {
120-
srcFile, ok := m.getSourceFile(genFile)
122+
for _, file := range m.specifiedFiles {
123+
srcFile, genFile, ok := m.getGoAndMDFile(file, m.assistantType)
121124
if ok {
122125
fileMap[srcFile] = genFile
123126
}
@@ -152,6 +155,30 @@ func (m *mergeParams) getSourceFile(file string) (string, bool) {
152155
return "", false
153156
}
154157

158+
func (m *mergeParams) getGoAndMDFile(file string, assistantType string) (goFile string, mdFile string, ok bool) {
159+
if strings.HasSuffix(file, ".go") {
160+
goFile = file
161+
mdFile = file + "." + assistantType + ".md"
162+
if gofile.IsExists(mdFile) {
163+
ok = true
164+
} else {
165+
ok = false
166+
}
167+
return goFile, mdFile, ok
168+
} else if strings.HasSuffix(file, getAssistantSuffixed(m.assistantType)) {
169+
mdFile = file
170+
goFile = strings.TrimSuffix(file, getAssistantSuffixed(m.assistantType)) + ".go"
171+
if gofile.IsExists(goFile) {
172+
ok = true
173+
} else {
174+
ok = false
175+
}
176+
return goFile, mdFile, ok
177+
}
178+
179+
return "", "", false
180+
}
181+
155182
func (m *mergeParams) mergeGoFile(srcFile string, genFile string) (string, error) {
156183
srcCode, err := os.ReadFile(srcFile)
157184
if err != nil {

0 commit comments

Comments
 (0)