refactor

package
v0.7.0-alpha.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 9 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL