Skip to content

feat(cli): add convenience filter flags --ext, --max-depth, --min-size, --max-size#101

Merged
gregpriday merged 1 commit into
developfrom
feature/issue-28-add-convenience-filter-flags
Feb 26, 2026
Merged

feat(cli): add convenience filter flags --ext, --max-depth, --min-size, --max-size#101
gregpriday merged 1 commit into
developfrom
feature/issue-28-add-convenience-filter-flags

Conversation

@gregpriday
Copy link
Copy Markdown
Owner

Summary

Adds four convenience CLI flags that make common file-filtering tasks fast and intuitive, without requiring glob patterns or profile edits.

Closes #28

Changes Made

New CLI flags (bin/copytree.js)

  • --ext <extensions> — filter by file extensions, comma-separated (e.g. .js,.ts,.tsx or js,ts)
  • --max-depth <n> — limit traversal depth (0 = root files only, 1 = one level deep, etc.)
  • --min-size <size> — exclude files smaller than a human-readable threshold (e.g. 1KB, 500B)
  • --max-size <size> — exclude files larger than a human-readable threshold (e.g. 10MB, 1GB)

Wiring (src/commands/copy.js)

  • Added parseExtensions() — normalises comma-separated extensions to lowercase with leading dots; throws CommandError for empty/degenerate input (e.g. ',,,)
  • Added parseSizeOption() — wraps existing parseSize() from helpers.js with a user-friendly CommandError
  • buildProfileFromCliOptions() — converts the four new flags into profile.options fields
  • setupPipelineStages() — forwards the new options to FileDiscoveryStage

Filtering logic (src/pipeline/stages/FileDiscoveryStage.js)

  • Constructor stores extFilter, maxDepth, minSizeBytes, maxSizeBytes
  • maxDepth is passed to both walkers via walkOptions
  • Extension and size filters are applied as post-filters in the discovery loop — AND logic with existing --filter patterns
  • Force-included files (--always / .copytreeinclude) bypass ext/size filters by design (separate fast-glob path)

Depth limiting (src/utils/ignoreWalker.js, src/utils/parallelWalker.js)

  • walkWithIgnorewalk() now accepts a depth parameter (default 0); recursion is skipped when depth >= maxDepth
  • walkParallel — BFS queue entries carry depth; subdirectories are only enqueued when depth < maxDepth
  • Both walkers use identical semantics; parity is verified by a cross-walker test

Tests

  • New tests/unit/pipeline/stages/FileDiscoveryStage.filters.test.js — 18 tests covering all four filters and their combinations
  • Extended tests/unit/utils/ignoreWalker.test.js — 4 maxDepth cases (0, 1, 2, unlimited)
  • Extended tests/unit/utils/parallelWalker.test.js — 5 maxDepth cases including sequential/parallel parity check

Usage Examples

# Only JavaScript/TypeScript files
copytree --ext .js,.ts

# Limit depth to 2 levels
copytree --max-depth 2

# Files between 1KB and 100KB
copytree --min-size 1KB --max-size 100KB

# Combined: Python files, 3 levels deep, under 50KB
copytree --ext .py --max-depth 3 --max-size 50KB

# Combined with existing --filter (AND logic)
copytree --filter "src/**" --ext .ts

…e, --max-size

- Add --ext flag to filter by file extensions (comma-separated, e.g. .js,.ts)
- Add --max-depth flag to limit directory traversal depth (0 = root only)
- Add --min-size / --max-size flags for human-readable size filtering (1KB, 10MB)
- Implement depth tracking in ignoreWalker.js (recursive) and parallelWalker.js (BFS)
- Apply extension and size filters in FileDiscoveryStage after discovery
- parseExtensions() validates non-empty input, throws CommandError on degenerate input
- parseSizeOption() reuses existing parseSize() from helpers with friendly error messages
- All four flags work in combination (AND logic) with existing --filter patterns
- Force-included files (--always / .copytreeinclude) bypass ext/size filters by design
- Add 18 unit tests for filter combinations in FileDiscoveryStage.filters.test.js
- Add 4 maxDepth tests to ignoreWalker.test.js
- Add 5 maxDepth tests to parallelWalker.test.js including sequential/parallel parity check
@gregpriday gregpriday merged commit 9000096 into develop Feb 26, 2026
11 of 15 checks passed
@gregpriday gregpriday deleted the feature/issue-28-add-convenience-filter-flags branch February 26, 2026 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add convenience filter flags for file selection

1 participant