Skip to content

Enhance CLI UI and add multi-select Title options for downloads#6

Merged
chris-c-thomas merged 6 commits intomainfrom
feat/tui
Mar 2, 2026
Merged

Enhance CLI UI and add multi-select Title options for downloads#6
chris-c-thomas merged 6 commits intomainfrom
feat/tui

Conversation

@chris-c-thomas
Copy link
Copy Markdown
Owner

@chris-c-thomas chris-c-thomas commented Mar 2, 2026

This pull request introduces a major update (v0.5.0) to the law2md CLI and documentation, focused on supporting multi-title selection for both download and convert commands, updating default paths, and improving terminal output. The changes provide a more flexible and user-friendly workflow for working with U.S. Code XML files, including new options for specifying multiple titles and enhanced summary reporting.

Multi-title selection and CLI enhancements

  • Added --titles <spec> option to both download and convert commands, supporting single numbers, comma-separated lists, ranges, and mixed formats; replaces the old --title <n> option and allows batch processing of titles. [1] [2] [3] [4] [5]
  • Updated the convert command to accept either a file path or --titles, with per-title summary tables and an aggregate footer showing conversion stats. [1] [2] [3]
  • Added --input-dir <dir> option to specify the XML directory for conversion (default: ./downloads/usc/xml). [1] [2] [3] [4]

Documentation and path updates

  • Updated documentation and examples to use the new default XML path downloads/usc/xml/ instead of xml/, reflecting the new workflow and options. [1] [2] [3] [4] [5] [6]
  • Updated .prettierignore to include downloads directory, aligning with the new file structure.

Terminal output and UI improvements

  • Integrated chalk, ora, and cli-table3 for polished CLI output, including spinners, formatted summary blocks, and data tables for download and convert commands. [1] [2] [3]

Version and metadata updates

  • Bumped package and generator version to 0.5.0 in package.json, output metadata, and documentation. [1] [2] [3] [4]
  • Updated changelogs to reflect new features and dependency bumps.

These changes collectively make the CLI more powerful and easier to use for batch operations and improve the clarity of both documentation and output.

Summary by CodeRabbit

  • New Features

    • Multi-title selection with --titles flag supporting ranges (e.g., 1-5), comma-separated values, and mixed formats for download and convert commands
    • Optional --input-dir parameter for convert command
    • Enhanced terminal UI with progress spinners, formatted tables, and colored output
    • Aggregate summaries for batch operations
  • Documentation

    • Updated CLI examples and file paths reflecting new --titles syntax and default download location
  • Tests

    • Added comprehensive test coverage for title parsing functionality
  • Chores

    • Version bumped to 0.5.0

  Replace --title <n> (single title) with --titles <spec> supporting
  ranges, comma-separated lists, and mixed formats (e.g. 1-5,8,11).
  Make convert <input> optional and add --titles + --input-dir flags
  for multi-title conversion with per-title summaries and aggregate footer.
@chris-c-thomas chris-c-thomas requested a review from Copilot March 2, 2026 03:17
@chris-c-thomas chris-c-thomas self-assigned this Mar 2, 2026
@chris-c-thomas chris-c-thomas added docs Improvements or additions to documentation enhancement Enhancements made to exisiting features or codebase feature New feature implemented labels Mar 2, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 2, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 9e15faf and dedb71f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (19)
  • .gitignore
  • .prettierignore
  • CHANGELOG.md
  • CLAUDE.md
  • CONTRIBUTING.md
  • README.md
  • docs/output-format.md
  • packages/cli/CHANGELOG.md
  • packages/cli/package.json
  • packages/cli/src/commands/convert.ts
  • packages/cli/src/commands/download.ts
  • packages/cli/src/index.test.ts
  • packages/cli/src/parse-titles.test.ts
  • packages/cli/src/parse-titles.ts
  • packages/cli/src/ui.ts
  • packages/core/CHANGELOG.md
  • packages/core/package.json
  • packages/usc/CHANGELOG.md
  • packages/usc/package.json

📝 Walkthrough

Walkthrough

The PR introduces version 0.5.0 with multi-title selection support via a new --titles flag (replacing --title), enabling batch operations with range and comma-separated specifications. New UI utilities provide formatted spinner, table, and summary output. Documentation and configuration are updated to reflect the download directory change from xml/ to downloads/usc/xml/.

Changes

Cohort / File(s) Summary
Configuration & Ignore Rules
.gitignore, .prettierignore
Updated download path from xml/ to downloads/; added downloads to Prettier ignore list.
Version & Dependencies
packages/cli/package.json, packages/core/package.json, packages/usc/package.json
Bumped all package versions from 0.4.0 to 0.5.0.
CLI Package Dependencies
packages/cli/package.json
Added runtime dependencies: chalk ^5.6.2, cli-table3 ^0.6.5, ora ^8.2.0 for enhanced terminal output.
Changelog Documentation
CHANGELOG.md, packages/cli/CHANGELOG.md, packages/core/CHANGELOG.md, packages/usc/CHANGELOG.md
Added 0.5.0 entries documenting multi-title selection feature and dependency updates; earlier versions (0.4.0, 0.4.1) retained.
User Documentation
README.md, CLAUDE.md, CONTRIBUTING.md, docs/output-format.md
Updated CLI examples to use --titles flag, changed file paths from xml/ to downloads/usc/xml/, added range and multi-title examples, updated generator version to 0.5.0.
Multi-Title Parsing
packages/cli/src/parse-titles.ts
New function parseTitles(input: string): number[] supporting single numbers, comma-separated lists, ranges (e.g., 1-5), and comprehensive validation for values 1-54.
Parse-Titles Tests
packages/cli/src/parse-titles.test.ts
Comprehensive test suite validating single numbers, ranges, comma-separated values, deduplication, sorting, whitespace handling, boundary cases, and error handling.
Terminal UI Utilities
packages/cli/src/ui.ts
New module exporting formatting and rendering helpers: createSpinner, formatDuration, formatBytes, formatNumber, heading, success, error, summaryBlock, and dataTable.
Download Command Implementation
packages/cli/src/commands/download.ts
Replaced --title with --titles for multi-title downloads; integrated new UI helpers (spinner, summary block, table) for structured output; updated validation and error handling.
Convert Command Implementation
packages/cli/src/commands/convert.ts
Added --titles and --input-dir options for batch conversion; introduced helper functions (buildConvertOptions, titleXmlPath, convertSingleFile) enabling per-title processing with aggregated summary output.
CLI Tests
packages/cli/src/index.test.ts
Updated test expectations to validate new --titles and --input-dir flags in help output; removed expectations for deprecated --title flag.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI
    participant Parser as Title Parser<br/>(parseTitles)
    participant Handler as Command Handler<br/>(download/convert)
    participant UI as UI Module<br/>(spinner, tables)
    participant FS as File System
    participant Converter as Converter/<br/>Downloader

    User->>CLI: Enter command with --titles spec
    CLI->>Parser: parseTitles(spec)
    Parser->>Parser: Parse ranges, lists,<br/>deduplicate, validate
    Parser-->>CLI: number[] of titles
    
    CLI->>Handler: Process titles array
    
    loop For each title
        Handler->>UI: createSpinner(title label)
        UI-->>Handler: spinner instance
        Handler->>FS: Resolve title file path
        FS-->>Handler: file path
        Handler->>Converter: Process single title
        Converter->>FS: Read/Write files
        FS-->>Converter: Success/Error
        Converter-->>Handler: Result + stats
        Handler->>UI: Update spinner + log
        UI-->>Handler: Output rendered
    end
    
    Handler->>UI: summaryBlock(aggregated stats)
    UI->>UI: Format table with<br/>totals, duration, size
    UI-->>Handler: Summary rendered
    Handler-->>CLI: Complete with results
    CLI-->>User: Display formatted output
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@chris-c-thomas chris-c-thomas merged commit 9221114 into main Mar 2, 2026
4 of 5 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR upgrades law2md CLI UX for batch workflows by adding multi-title selection for download/convert, a configurable XML input directory for multi-title conversion, and more polished terminal output. It also updates default paths/documentation and bumps versions to 0.5.0.

Changes:

  • Add --titles <spec> parsing (ranges/lists) and apply it to download and convert (including multi-title convert mode with aggregate stats).
  • Introduce shared terminal UI helpers (spinner, tables, formatting) and adopt chalk/ora/cli-table3.
  • Update defaults/docs/ignores to the new ./downloads/usc/xml layout and bump package versions/changelogs.

Reviewed changes

Copilot reviewed 18 out of 20 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
pnpm-lock.yaml Locks new CLI UI dependencies (chalk, ora, cli-table3) and transitive deps.
packages/usc/package.json Bumps @law2md/usc version to 0.5.0.
packages/usc/CHANGELOG.md Adds release notes for @law2md/usc (currently includes CLI-oriented notes).
packages/core/package.json Bumps @law2md/core version to 0.5.0.
packages/core/CHANGELOG.md Adds release notes for @law2md/core (currently includes CLI-oriented notes).
packages/cli/src/ui.ts Adds shared CLI UI utilities (spinner, formatting, tables).
packages/cli/src/parse-titles.ts Implements --titles spec parsing with validation/dedup/sort.
packages/cli/src/parse-titles.test.ts Adds unit tests for parseTitles().
packages/cli/src/index.test.ts Updates CLI help expectations for --titles / --input-dir.
packages/cli/src/commands/download.ts Replaces --title with --titles and adds formatted summary/table output.
packages/cli/src/commands/convert.ts Makes [input] optional; adds --titles + --input-dir multi-title conversion path and summaries.
packages/cli/package.json Bumps CLI version and adds new UI dependencies.
packages/cli/CHANGELOG.md Updates CLI changelog for 0.5.0 with multi-title selection.
docs/output-format.md Updates generator version strings to 0.5.0.
README.md Updates examples/docs to --titles and new default downloads path.
CONTRIBUTING.md Updates contributor docs/examples for new CLI options and downloads path.
CLAUDE.md Updates repo layout + dev commands to reflect downloads/usc/xml and multi-title usage.
CHANGELOG.md Adds project-level 0.5.0 release notes and related prior entries.
.prettierignore Adds downloads/ to ignored paths.
.gitignore Updates ignored download locations and documents legacy paths.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/cli/src/ui.ts
Comment on lines +21 to +22
const mins = Math.floor(secs / 60);
const remainSecs = Math.round(secs % 60);
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatDuration() can produce invalid strings like "1m 60s" because remainSecs uses Math.round(secs % 60), which can round up to 60. Consider using Math.floor for the seconds component (or carrying the extra second into minutes) to keep the 0–59 invariant.

Suggested change
const mins = Math.floor(secs / 60);
const remainSecs = Math.round(secs % 60);
const totalSecs = Math.round(secs);
const mins = Math.floor(totalSecs / 60);
const remainSecs = totalSecs % 60;

Copilot uses AI. Check for mistakes.
Comment on lines +38 to 42
// Validate: must specify --titles or --all
if (!options.titles && !options.all) {
console.error(error("Specify --titles <spec> or --all (e.g. --titles 1-5,8,11)"));
process.exit(1);
}
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI currently allows --titles and --all to be provided together; in that case --all is silently ignored because titles is passed to downloadTitles(). It’d be clearer to treat these flags as mutually exclusive and exit with an error when both are present.

Copilot uses AI. Check for mistakes.
Comment on lines 103 to 107
if (result.errors.length > 0) {
console.log("");
for (const err of result.errors) {
console.error(` Error (Title ${err.titleNumber}): ${err.message}`);
console.log(` ${error(`Title ${err.titleNumber}: ${err.message}`)}`);
}
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Download errors are printed with console.log(...) (stdout). For scripting/piping, error reporting should generally go to stderr (e.g., console.error(...)) while the success tables remain on stdout.

Copilot uses AI. Check for mistakes.

### Minor Changes

- 3a29a8e: Add `--titles` multi-select option to download and convert commands. Supports ranges (`1-5`), comma-separated lists
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package changelog entry describes CLI flags (--titles on download/convert). Those options are implemented in packages/cli, not in @law2md/core, so the 0.5.0 notes here look inaccurate/misleading. Suggest updating this entry to describe actual @law2md/core changes (or omit it if there were no functional changes).

Suggested change
- 3a29a8e: Add `--titles` multi-select option to download and convert commands. Supports ranges (`1-5`), comma-separated lists
- 3a29a8e: No functional changes to `@law2md/core` in this release; version bump to keep in sync with other packages.

Copilot uses AI. Check for mistakes.

### Patch Changes

- Add chalk, ora, and cli-table3 for polished terminal output with spinners and formatted
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 0.4.1 patch notes mention adding chalk, ora, and cli-table3, but those dependencies are in the CLI package (and packages/cli/src/ui.ts), not @law2md/core. This changelog entry should reflect changes shipped in @law2md/core only.

Suggested change
- Add chalk, ora, and cli-table3 for polished terminal output with spinners and formatted
- Internal maintenance release for @law2md/core (no public API changes).

Copilot uses AI. Check for mistakes.
Comment thread packages/usc/CHANGELOG.md

### Minor Changes

- 3a29a8e: Add `--titles` multi-select option to download and convert commands. Supports ranges (`1-5`), comma-separated lists
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This @law2md/usc changelog entry calls out the CLI --titles option on the download/convert commands. That flag parsing lives in packages/cli; @law2md/usc exposes downloadTitles()/convertTitle() and doesn’t implement CLI options itself. Recommend rewriting the 0.5.0 notes to reflect actual library/API changes (or remove if this release is just a version bump).

Suggested change
- 3a29a8e: Add `--titles` multi-select option to download and convert commands. Supports ranges (`1-5`), comma-separated lists
- 3a29a8e: Add multi-title helpers (`downloadTitles()`, `convertTitle()`) to support downloading and converting multiple titles. Supports ranges (`1-5`) and comma-separated lists.

Copilot uses AI. Check for mistakes.
Comment thread packages/usc/CHANGELOG.md

### Patch Changes

- Add chalk, ora, and cli-table3 for polished terminal output with spinners and formatted
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 0.4.1 notes mention adding chalk, ora, and cli-table3 for terminal output, but those dependencies/utilities are in the CLI package rather than @law2md/usc. This entry is likely misplaced and should be corrected to avoid misleading package consumers.

Suggested change
- Add chalk, ora, and cli-table3 for polished terminal output with spinners and formatted
- Internal maintenance; terminal output improvements (chalk, ora, cli-table3) are part of the CLI package, not `@law2md/usc`.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation enhancement Enhancements made to exisiting features or codebase feature New feature implemented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants