diff --git a/cmd/root.go b/cmd/root.go index 63caa4c..fb59c15 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -50,7 +50,11 @@ Examples: dirmd -i # Pick specific files in vertical slices mode - dirmd -o ./docs ~/repos/myproject --vertical-slices --pick common/src/lib.rs --pick mssql-extractor/src/processor.rs`, + dirmd -o ./docs ~/repos/myproject --vertical-slices \ + --pick common/src/config.rs --pick init/src/main.rs + + # Pick all files as individual picks + dirmd -o ./docs ~/repos/myproject --vertical-slices --pick-all`, RunE: run, } @@ -72,6 +76,7 @@ Examples: tuiMode bool instructions bool pickPaths []string + pickAll bool ) func Execute() { @@ -99,6 +104,7 @@ func init() { rootCmd.Flags().BoolVar(&omitMd, "omit-md", false, "omit all .md files except README.md") rootCmd.Flags().BoolVar(&instructions, "instructions", false, "include .dirmd instructions file if present in root") rootCmd.Flags().StringArrayVar(&pickPaths, "pick", nil, "repeatable: relative path to file to include as pick (requires --vertical-slices)") + rootCmd.Flags().BoolVar(&pickAll, "pick-all", false, "include all discovered files as individual picks (requires --vertical-slices)") } func run(cmd *cobra.Command, args []string) error { @@ -130,6 +136,14 @@ func run(cmd *cobra.Command, args []string) error { return fmt.Errorf("--pick requires --vertical-slices") } + if pickAll && !verticalSlices { + return fmt.Errorf("--pick-all requires --vertical-slices") + } + + if pickAll && len(pickPaths) > 0 { + return fmt.Errorf("--pick-all and --pick cannot be used together") + } + excludedExts := append(config.DefaultExts, extensions...) if skipFrontend { excludedExts = append(excludedExts, config.FrontendExts...) @@ -152,6 +166,7 @@ func run(cmd *cobra.Command, args []string) error { OmitMd: omitMd, IncludeInstructions: instructions, PickPaths: pickPaths, + PickAll: pickAll, } if singleFile != "" { diff --git a/internal/config/config.go b/internal/config/config.go index 947dba5..038f546 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -54,4 +54,5 @@ type Config struct { OmitMd bool IncludeInstructions bool PickPaths []string + PickAll bool } diff --git a/internal/renderer/renderer.go b/internal/renderer/renderer.go index 397115a..ba6edbb 100644 --- a/internal/renderer/renderer.go +++ b/internal/renderer/renderer.go @@ -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) }