introduce pick-all
This commit is contained in:
@@ -54,4 +54,5 @@ type Config struct {
|
||||
OmitMd bool
|
||||
IncludeInstructions bool
|
||||
PickPaths []string
|
||||
PickAll bool
|
||||
}
|
||||
|
||||
@@ -153,7 +153,33 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e
|
||||
|
||||
pickInfos := make([]PickInfo, 0)
|
||||
|
||||
if len(result.Cfg.PickPaths) > 0 {
|
||||
// Handle --pick-all: collect all entries as individual picks
|
||||
if result.Cfg.PickAll {
|
||||
for _, entry := range entries {
|
||||
parts := strings.Split(entry.RelPath, string(filepath.Separator))
|
||||
sliceDir := outputDir
|
||||
if len(parts) > 1 {
|
||||
sliceDir = filepath.Join(outputDir, parts[0])
|
||||
if err := os.MkdirAll(sliceDir, 0755); err != nil {
|
||||
return nil, fmt.Errorf("cannot create pick slice directory %s: %w", sliceDir, err)
|
||||
}
|
||||
}
|
||||
|
||||
sliceName := filepath.Base(entry.RelPath) + ".md"
|
||||
pickPathOut := filepath.Join(sliceDir, sliceName)
|
||||
|
||||
if err := writePickFile(pickPathOut, absRoot, entry.RelPath, result.OmitTest, result.Commit, result.Cfg); err != nil {
|
||||
return nil, fmt.Errorf("failed to write pick %s: %w", entry.RelPath, err)
|
||||
}
|
||||
|
||||
pickInfos = append(pickInfos, PickInfo{
|
||||
RelPath: entry.RelPath,
|
||||
FileType: sliceName,
|
||||
SliceDir: filepath.Base(sliceDir),
|
||||
})
|
||||
}
|
||||
} else if len(result.Cfg.PickPaths) > 0 {
|
||||
var err error
|
||||
pickInfos, err = writePickFiles(absRoot, outputDir, result.Cfg, result.OmitTest, result.Commit)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to write pick files: %w", err)
|
||||
@@ -161,6 +187,13 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e
|
||||
generated = append(generated, pickInfoPaths(pickInfos)...)
|
||||
}
|
||||
|
||||
// Ensure generated includes pick files from --pick-all
|
||||
if result.Cfg.PickAll {
|
||||
for _, p := range pickInfos {
|
||||
generated = append(generated, filepath.Join(p.SliceDir, p.FileType))
|
||||
}
|
||||
}
|
||||
|
||||
if err := writeRootIndex(rootPath, absRoot, rootName, repoName, topLevelDirs, rootFiles, result.Commit, result.Instructions, treeRoot, result.Cfg, pickInfos); err != nil {
|
||||
return nil, fmt.Errorf("failed to write root index: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user