Documentation
¶
Overview ¶
Package refactor provides the command to generate refactoring prompts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RefactorCmd = &cobra.Command{ Use: "refactor [files...]", Short: "Generates a prompt for AI-assisted code refactoring.", Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { presenter := ui.NewPresenter(cmd.OutOrStdout(), cmd.ErrOrStderr()) tmpl, err := template.New("refactor-prompt").Parse(refactorPromptTemplate) if err != nil { return fmt.Errorf("failed to parse prompt template: %w", err) } var promptBuf bytes.Buffer if err := tmpl.Execute(&promptBuf, nil); err != nil { return fmt.Errorf("failed to render prompt template: %w", err) } // 2. Read and Format File Content var codeContent strings.Builder for _, filePath := range args { content, err := os.ReadFile(filePath) if err != nil { return fmt.Errorf("failed to read file '%s': %w", filePath, err) } codeContent.WriteString(fmt.Sprintf("\n--- FILE: %s ---\n", filePath)) codeContent.WriteString("```go\n") codeContent.Write(content) codeContent.WriteString("\n```\n") } presenter.Header("--- Copy the text below to your AI ---") fmt.Println(promptBuf.String()) fmt.Println(codeContent.String()) presenter.Header("--- End of Prompt ---") presenter.Success("Refactoring prompt generated for %d file(s).", len(args)) return nil }, }
RefactorCmd represents the craft refactor command.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.