first mvp

This commit is contained in:
2026-05-16 01:39:45 +08:00
parent b3a2ae4681
commit 69afb0a53e
13 changed files with 205 additions and 272 deletions
-36
View File
@@ -1,36 +0,0 @@
package cmd
import (
"fmt"
"cliprepo/internal/bundle"
"github.com/spf13/cobra"
)
var bundleClipboard bool
var bundleCmd = &cobra.Command{
Use: "bundle [key]",
Short: "Bundle files by key from config",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
key := args[0]
result, err := bundle.Build(key)
if err != nil {
return err
}
if bundleClipboard {
return bundle.Copy(result)
}
fmt.Println(result)
return nil
},
}
func init() {
rootCmd.AddCommand(bundleCmd)
bundleCmd.Flags().BoolVar(&bundleClipboard, "clipboard", false, "Copy to clipboard")
}
+9
View File
@@ -0,0 +1,9 @@
package cmd
import (
"github.com/atotto/clipboard"
)
func copyToClipboard(content string) error {
return clipboard.WriteAll(content)
}
+1 -1
View File
@@ -8,7 +8,7 @@ import (
var rootCmd = &cobra.Command{
Use: "cliprepo",
Short: "Extract repo structure and bundle code for LLMs",
Short: "LLM context builder from repo",
}
func Execute() {
+93
View File
@@ -0,0 +1,93 @@
package cmd
import (
"fmt"
"os"
"path/filepath"
"strings"
"cliprepo/internal/config"
"cliprepo/internal/tree"
"cliprepo/internal/utils"
"github.com/spf13/cobra"
"github.com/atotto/clipboard"
)
var delineate string
var useClipboard bool
var runCmd = &cobra.Command{
Use: "run",
Short: "Generate LLM context from repo",
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := config.Load()
if err != nil {
return err
}
// 1. tree
treeStr, err := tree.Generate(".")
if err != nil {
return err
}
var builder strings.Builder
builder.WriteString("===== PROJECT TREE =====\n")
builder.WriteString(treeStr)
builder.WriteString("\n\n")
// 2. preset files
rawFiles, ok := cfg.Preset[delineate]
if !ok {
return fmt.Errorf("preset not found: %s", delineate)
}
files, err := utils.ExpandGlob(rawFiles)
if err != nil {
return err
}
// 3. template
template := cfg.Prompts.Preset
for _, file := range files {
content, err := os.ReadFile(file)
if err != nil {
continue
}
path := file
if cfg.Config.PathMode == "absolute" {
abs, _ := filepath.Abs(file)
path = abs
}
block := strings.ReplaceAll(template, "{{path}}", path)
block = strings.ReplaceAll(block, "{{content}}", string(content))
builder.WriteString(block)
builder.WriteString("\n\n")
}
result := builder.String()
if useClipboard {
return clipboard.WriteAll(result)
}
fmt.Println(result)
return nil
},
}
func init() {
rootCmd.AddCommand(runCmd)
runCmd.Flags().StringVar(&delineate, "delineate", "", "preset key")
runCmd.Flags().BoolVar(&useClipboard, "clipboard", false, "copy output to clipboard")
}
-40
View File
@@ -1,40 +0,0 @@
package cmd
import (
"fmt"
"cliprepo/internal/tree"
"github.com/spf13/cobra"
)
var treeOutput string
var treeClipboard bool
var treeCmd = &cobra.Command{
Use: "tree",
Short: "Print repo tree respecting .gitignore",
RunE: func(cmd *cobra.Command, args []string) error {
result, err := tree.Generate(".")
if err != nil {
return err
}
if treeClipboard {
return tree.Copy(result)
}
if treeOutput != "" {
return tree.Write(treeOutput, result)
}
fmt.Println(result)
return nil
},
}
func init() {
rootCmd.AddCommand(treeCmd)
treeCmd.Flags().StringVarP(&treeOutput, "output", "o", "", "Output file")
treeCmd.Flags().BoolVar(&treeClipboard, "clipboard", false, "Copy to clipboard")
}