remove small-tree flag and only option to have bread crumbs in sub index files
This commit is contained in:
@@ -71,7 +71,6 @@ Examples:
|
|||||||
tuiMode bool
|
tuiMode bool
|
||||||
instructions bool
|
instructions bool
|
||||||
pickPaths []string
|
pickPaths []string
|
||||||
smallTree bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
@@ -99,7 +98,6 @@ func init() {
|
|||||||
rootCmd.Flags().BoolVar(&omitMd, "omit-md", false, "omit all .md files except README.md")
|
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().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().StringArrayVar(&pickPaths, "pick", nil, "repeatable: relative path to file to include as pick (requires --vertical-slices)")
|
||||||
rootCmd.Flags().BoolVar(&smallTree, "small-tree", false, "use breadcrumb-only tree for picked files (default: full tree)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(cmd *cobra.Command, args []string) error {
|
func run(cmd *cobra.Command, args []string) error {
|
||||||
@@ -153,7 +151,6 @@ func run(cmd *cobra.Command, args []string) error {
|
|||||||
OmitMd: omitMd,
|
OmitMd: omitMd,
|
||||||
IncludeInstructions: instructions,
|
IncludeInstructions: instructions,
|
||||||
PickPaths: pickPaths,
|
PickPaths: pickPaths,
|
||||||
SmallTree: smallTree,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if singleFile != "" {
|
if singleFile != "" {
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ type Config struct {
|
|||||||
OmitMd bool
|
OmitMd bool
|
||||||
IncludeInstructions bool
|
IncludeInstructions bool
|
||||||
PickPaths []string
|
PickPaths []string
|
||||||
SmallTree bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintUsage() {
|
func PrintUsage() {
|
||||||
@@ -97,7 +96,6 @@ func Parse() (*Config, error) {
|
|||||||
omitMd bool
|
omitMd bool
|
||||||
includeInstructions bool
|
includeInstructions bool
|
||||||
pickPaths stringSlice
|
pickPaths stringSlice
|
||||||
smallTree bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
flag.StringVar(&input, "i", "", "single file input (append mode only)")
|
flag.StringVar(&input, "i", "", "single file input (append mode only)")
|
||||||
@@ -118,7 +116,6 @@ func Parse() (*Config, error) {
|
|||||||
flag.BoolVar(&omitMd, "omit-md", false, "omit all .md files except README.md")
|
flag.BoolVar(&omitMd, "omit-md", false, "omit all .md files except README.md")
|
||||||
flag.BoolVar(&includeInstructions, "instructions", false, "include .dirmd instructions file if present in root")
|
flag.BoolVar(&includeInstructions, "instructions", false, "include .dirmd instructions file if present in root")
|
||||||
flag.Var(&pickPaths, "pick", "repeatable: relative path to file to include as pick (requires --vertical-slices)")
|
flag.Var(&pickPaths, "pick", "repeatable: relative path to file to include as pick (requires --vertical-slices)")
|
||||||
flag.BoolVar(&smallTree, "small-tree", false, "use breadcrumb-only tree for picked files (default: full tree)")
|
|
||||||
|
|
||||||
flag.Usage = PrintUsage
|
flag.Usage = PrintUsage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@@ -169,7 +166,6 @@ func Parse() (*Config, error) {
|
|||||||
OmitMd: omitMd,
|
OmitMd: omitMd,
|
||||||
IncludeInstructions: includeInstructions,
|
IncludeInstructions: includeInstructions,
|
||||||
PickPaths: pickPaths,
|
PickPaths: pickPaths,
|
||||||
SmallTree: smallTree,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if input != "" {
|
if input != "" {
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e
|
|||||||
pickInfos := make([]PickInfo, 0)
|
pickInfos := make([]PickInfo, 0)
|
||||||
|
|
||||||
if len(result.Cfg.PickPaths) > 0 {
|
if len(result.Cfg.PickPaths) > 0 {
|
||||||
pickInfos, err = writePickFiles(absRoot, absRoot, outputDir, result.Cfg, result.OmitTest, result.Commit, treeRoot, result.Cfg.SmallTree)
|
pickInfos, err = writePickFiles(absRoot, outputDir, result.Cfg, result.OmitTest, result.Commit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to write pick files: %w", err)
|
return nil, fmt.Errorf("failed to write pick files: %w", err)
|
||||||
}
|
}
|
||||||
@@ -165,7 +165,7 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e
|
|||||||
return nil, fmt.Errorf("failed to write root index: %w", err)
|
return nil, fmt.Errorf("failed to write root index: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := writeRootSliceFile(rootSlicePath, absRoot, rootName, rootFiles, result.OmitTest, result.Commit, result.Cfg); err != nil {
|
if err := writeRootSliceFile(rootSlicePath, absRoot, rootFiles, result.OmitTest, result.Commit, result.Cfg); err != nil {
|
||||||
return nil, fmt.Errorf("failed to write root slice: %w", err)
|
return nil, fmt.Errorf("failed to write root slice: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ func WriteSlices(result *walker.Result, outputDir, repoName string) ([]string, e
|
|||||||
absDir := filepath.Join(absRoot, dirName)
|
absDir := filepath.Join(absRoot, dirName)
|
||||||
dirEntries := topLevelDirs[dirName]
|
dirEntries := topLevelDirs[dirName]
|
||||||
|
|
||||||
if err := writeDirSlice(slicePath, absDir, absRoot, dirName, dirEntries, indexBasename, result.OmitTest, result.Commit, treeRoot, result.Cfg); err != nil {
|
if err := writeDirSlice(slicePath, absDir, absRoot, dirName, dirEntries, indexBasename, result.OmitTest, result.Commit, result.Cfg); err != nil {
|
||||||
return nil, fmt.Errorf("failed to write slice %s: %w", sliceName, err)
|
return nil, fmt.Errorf("failed to write slice %s: %w", sliceName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,7 +203,7 @@ func pickInfoPaths(picks []PickInfo) []string {
|
|||||||
return paths
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
func writePickFiles(absRoot, baseRoot, outputDir string, cfg *config.Config, omitTest bool, commit *git.CommitInfo, treeRoot *tree.Node, smallTree bool) ([]PickInfo, error) {
|
func writePickFiles(absRoot, outputDir string, cfg *config.Config, omitTest bool, commit *git.CommitInfo) ([]PickInfo, error) {
|
||||||
var pickInfos []PickInfo
|
var pickInfos []PickInfo
|
||||||
|
|
||||||
for _, pickPath := range cfg.PickPaths {
|
for _, pickPath := range cfg.PickPaths {
|
||||||
@@ -218,9 +218,8 @@ func writePickFiles(absRoot, baseRoot, outputDir string, cfg *config.Config, omi
|
|||||||
return nil, fmt.Errorf("pick path must be a file: %s", pickPath)
|
return nil, fmt.Errorf("pick path must be a file: %s", pickPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate file passes filters
|
|
||||||
name := filepath.Base(pickPath)
|
name := filepath.Base(pickPath)
|
||||||
filter := &filter.Filter{
|
flt := &filter.Filter{
|
||||||
MaxSize: cfg.MaxSize,
|
MaxSize: cfg.MaxSize,
|
||||||
Extensions: cfg.Extensions,
|
Extensions: cfg.Extensions,
|
||||||
Ignores: cfg.Ignores,
|
Ignores: cfg.Ignores,
|
||||||
@@ -229,11 +228,10 @@ func writePickFiles(absRoot, baseRoot, outputDir string, cfg *config.Config, omi
|
|||||||
OmitMd: cfg.OmitMd,
|
OmitMd: cfg.OmitMd,
|
||||||
}
|
}
|
||||||
|
|
||||||
if filter.ShouldSkipFile(fullPath, name, info) {
|
if flt.ShouldSkipFile(fullPath, name, info) {
|
||||||
return nil, fmt.Errorf("pick path %s filtered by active rules", pickPath)
|
return nil, fmt.Errorf("pick path %s filtered by active rules", pickPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine slice dir from first path segment
|
|
||||||
parts := strings.Split(pickPath, string(filepath.Separator))
|
parts := strings.Split(pickPath, string(filepath.Separator))
|
||||||
sliceDir := outputDir
|
sliceDir := outputDir
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
@@ -241,15 +239,12 @@ func writePickFiles(absRoot, baseRoot, outputDir string, cfg *config.Config, omi
|
|||||||
if err := os.MkdirAll(sliceDir, 0755); err != nil {
|
if err := os.MkdirAll(sliceDir, 0755); err != nil {
|
||||||
return nil, fmt.Errorf("cannot create pick slice directory %s: %w", sliceDir, err)
|
return nil, fmt.Errorf("cannot create pick slice directory %s: %w", sliceDir, err)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Root-level pick
|
|
||||||
sliceDir = outputDir
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sliceName := filepath.Base(pickPath) + ".md"
|
sliceName := filepath.Base(pickPath) + ".md"
|
||||||
pickPathOut := filepath.Join(sliceDir, sliceName)
|
pickPathOut := filepath.Join(sliceDir, sliceName)
|
||||||
|
|
||||||
if err := writePickFile(pickPathOut, absRoot, pickPath, omitTest, commit, cfg, treeRoot, smallTree); err != nil {
|
if err := writePickFile(pickPathOut, absRoot, pickPath, omitTest, commit, cfg); err != nil {
|
||||||
return nil, fmt.Errorf("failed to write pick %s: %w", pickPath, err)
|
return nil, fmt.Errorf("failed to write pick %s: %w", pickPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +258,7 @@ func writePickFiles(absRoot, baseRoot, outputDir string, cfg *config.Config, omi
|
|||||||
return pickInfos, nil
|
return pickInfos, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func writePickFile(path, absRoot, relPath string, omitTest bool, commit *git.CommitInfo, cfg *config.Config, treeRoot *tree.Node, smallTree bool) error {
|
func writePickFile(path, absRoot, relPath string, omitTest bool, commit *git.CommitInfo, cfg *config.Config) error {
|
||||||
f, err := os.Create(path)
|
f, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create pick file: %w", err)
|
return fmt.Errorf("cannot create pick file: %w", err)
|
||||||
@@ -276,6 +271,7 @@ func writePickFile(path, absRoot, relPath string, omitTest bool, commit *git.Com
|
|||||||
fmt.Fprintf(&sb, "> Generated: %s\n", time.Now().Format(time.RFC3339))
|
fmt.Fprintf(&sb, "> Generated: %s\n", time.Now().Format(time.RFC3339))
|
||||||
sb.WriteString(git.FormatCommitLine(commit))
|
sb.WriteString(git.FormatCommitLine(commit))
|
||||||
sb.WriteString(FormatFlags(cfg))
|
sb.WriteString(FormatFlags(cfg))
|
||||||
|
fmt.Fprintf(&sb, "Root document: index_%s.md\n\n", filepath.Base(absRoot))
|
||||||
|
|
||||||
fullPath := filepath.Join(absRoot, relPath)
|
fullPath := filepath.Join(absRoot, relPath)
|
||||||
content, err := readFileForOutput(fullPath, omitTest)
|
content, err := readFileForOutput(fullPath, omitTest)
|
||||||
@@ -285,15 +281,7 @@ func writePickFile(path, absRoot, relPath string, omitTest bool, commit *git.Com
|
|||||||
language := extToLang(filepath.Ext(relPath))
|
language := extToLang(filepath.Ext(relPath))
|
||||||
lines := countLines(content)
|
lines := countLines(content)
|
||||||
|
|
||||||
if smallTree {
|
fmt.Fprintf(&sb, "Tree: %s\n\n", tree.RenderBreadcrumb(absRoot, relPath))
|
||||||
breadcrumb := tree.RenderBreadcrumb(absRoot, relPath)
|
|
||||||
fmt.Fprintf(&sb, "Tree: %s\n\n", breadcrumb)
|
|
||||||
} else {
|
|
||||||
sb.WriteString("## Directory Tree\n\n")
|
|
||||||
sb.WriteString(fenceChars + "\n")
|
|
||||||
sb.WriteString(renderTreeWithLegend(treeRoot, filepath.Base(absRoot)))
|
|
||||||
sb.WriteString(fenceChars + "\n\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(&sb, "--- FILE: ./%s (%d bytes, %d lines) ---\n", relPath, infoSize(fullPath), lines)
|
fmt.Fprintf(&sb, "--- FILE: ./%s (%d bytes, %d lines) ---\n", relPath, infoSize(fullPath), lines)
|
||||||
sb.WriteString(fenceChars)
|
sb.WriteString(fenceChars)
|
||||||
@@ -305,7 +293,7 @@ func writePickFile(path, absRoot, relPath string, omitTest bool, commit *git.Com
|
|||||||
if !strings.HasSuffix(content, "\n") {
|
if !strings.HasSuffix(content, "\n") {
|
||||||
sb.WriteString("\n")
|
sb.WriteString("\n")
|
||||||
}
|
}
|
||||||
sb.WriteString(fmt.Sprintf("%s\n--- END FILE ---\n\n", fenceChars))
|
fmt.Fprintf(&sb, "%s\n--- END FILE ---\n\n", fenceChars)
|
||||||
|
|
||||||
_, err = f.WriteString(sb.String())
|
_, err = f.WriteString(sb.String())
|
||||||
return err
|
return err
|
||||||
@@ -378,7 +366,7 @@ func writeRootIndex(path, absRoot, rootName, repoName string, topLevelDirs map[s
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeRootSliceFile(path, absRoot, rootName string, rootFiles []walker.Entry, omitTest bool, commit *git.CommitInfo, cfg *config.Config) error {
|
func writeRootSliceFile(path, absRoot string, rootFiles []walker.Entry, omitTest bool, commit *git.CommitInfo, cfg *config.Config) error {
|
||||||
f, err := os.Create(path)
|
f, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create root slice file: %w", err)
|
return fmt.Errorf("cannot create root slice file: %w", err)
|
||||||
@@ -391,7 +379,8 @@ func writeRootSliceFile(path, absRoot, rootName string, rootFiles []walker.Entry
|
|||||||
sb.WriteString(git.FormatCommitLine(commit))
|
sb.WriteString(git.FormatCommitLine(commit))
|
||||||
sb.WriteString(FormatFlags(cfg))
|
sb.WriteString(FormatFlags(cfg))
|
||||||
|
|
||||||
sb.WriteString("Root contents: all files at the repository root level.\n\n")
|
rootName := filepath.Base(absRoot)
|
||||||
|
fmt.Fprintf(&sb, "Tree: %s /\n\n", rootName)
|
||||||
|
|
||||||
if len(rootFiles) == 0 {
|
if len(rootFiles) == 0 {
|
||||||
sb.WriteString("(none)\n")
|
sb.WriteString("(none)\n")
|
||||||
@@ -425,7 +414,7 @@ func writeRootSliceFile(path, absRoot, rootName string, rootFiles []walker.Entry
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeDirSlice(path, absDir, absRoot, dirName string, fileEntries []walker.Entry, rootFileName string, omitTest bool, commit *git.CommitInfo, treeRoot *tree.Node, cfg *config.Config) error {
|
func writeDirSlice(path, absDir, absRoot, dirName string, fileEntries []walker.Entry, rootFileName string, omitTest bool, commit *git.CommitInfo, cfg *config.Config) error {
|
||||||
f, err := os.Create(path)
|
f, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create slice file: %w", err)
|
return fmt.Errorf("cannot create slice file: %w", err)
|
||||||
@@ -439,10 +428,7 @@ func writeDirSlice(path, absDir, absRoot, dirName string, fileEntries []walker.E
|
|||||||
sb.WriteString(FormatFlags(cfg))
|
sb.WriteString(FormatFlags(cfg))
|
||||||
fmt.Fprintf(&sb, "Root document: %s\n\n", rootFileName)
|
fmt.Fprintf(&sb, "Root document: %s\n\n", rootFileName)
|
||||||
|
|
||||||
sb.WriteString("## Directory Tree\n\n")
|
fmt.Fprintf(&sb, "Tree: %s / %s\n\n", filepath.Base(absRoot), dirName)
|
||||||
sb.WriteString(fenceChars + "\n")
|
|
||||||
sb.WriteString(renderTreeWithLegend(treeRoot, filepath.Base(absDir)))
|
|
||||||
sb.WriteString(fenceChars + "\n\n")
|
|
||||||
|
|
||||||
if len(fileEntries) > 0 {
|
if len(fileEntries) > 0 {
|
||||||
sb.WriteString("## Contents\n\n")
|
sb.WriteString("## Contents\n\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user