mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-05 16:24:11 +08:00
feat: Add CodeSnippet entity and related functionality
- Introduced CodeSnippet schema with fields for snippet details and relationships to WorkspaceFile. - Enhanced WorkspaceFileUpdate and WorkspaceFileUpdateOne to manage snippets, including adding, removing, and clearing snippet relationships. - Updated Swagger documentation to include new API endpoints for CLI command execution and workspace file management. - Implemented domain structures for handling code files and AST parsing results. - Refactored Workspace and WorkspaceFile use cases to support new functionalities. - Adjusted CLI command execution to handle code file information in JSON format. - Improved error handling and logging throughout the workspace and file management processes.
This commit is contained in:
@@ -8,30 +8,34 @@ import (
|
||||
"github.com/chaitin/MonkeyCode/backend/domain"
|
||||
)
|
||||
|
||||
// RunCli
|
||||
// @Tags WorkspaceFile
|
||||
// @Description: 运行ctcode-cli命令
|
||||
// @param command 命令
|
||||
// @param flag [ -m | --maxlines <int> ] 解析时允许的最大 CodeSnippet 行数
|
||||
// @param codeFiles 代码文件信息
|
||||
// @return string 输出结果
|
||||
// @return error
|
||||
// RunCli 运行ctcode-cli命令
|
||||
//
|
||||
// @Tags CLI
|
||||
// @Summary 运行ctcode-cli命令
|
||||
// @Description 运行ctcode-cli命令
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param command path string true "命令"
|
||||
// @Param flag query string false "标志"
|
||||
// @Param codeFiles body domain.CodeFiles true "代码文件信息"
|
||||
// @Success 200 {object} []domain.IndexResult "输出结果"
|
||||
// @Failure 500 {object} web.Resp "内部错误"
|
||||
// @Router /api/v1/cli/{command} [post]
|
||||
func RunCli(command string, flag string, codeFiles domain.CodeFiles) ([]domain.IndexResult, error) {
|
||||
inputJson, err := json.Marshal(codeFiles)
|
||||
inputJson, err := json.Marshal(codeFiles)
|
||||
if err != nil {
|
||||
return []domain.IndexResult{}, err
|
||||
}
|
||||
cmd := exec.Command("ctcode-cli", command, flag, string(inputJson))
|
||||
cmd.Env = os.Environ()
|
||||
output, err := cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
return []domain.IndexResult{}, err
|
||||
}
|
||||
var res []domain.IndexResult
|
||||
err = json.Unmarshal(output, &res)
|
||||
if err!= nil {
|
||||
return []domain.IndexResult{}, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
cmd := exec.Command("ctcode-cli", command, flag, string(inputJson))
|
||||
cmd.Env = os.Environ()
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return []domain.IndexResult{}, err
|
||||
}
|
||||
var res []domain.IndexResult
|
||||
err = json.Unmarshal(output, &res)
|
||||
if err != nil {
|
||||
return []domain.IndexResult{}, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user