feat: Add list-formats command and central format registry #861
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #859
This PR addresses several CLI user experience issues related to discovering supported formats by introducing a central format registry and a new
list-formatssubcommand. The previous approach had inconsistent, out-of-date, and context-unaware hints for formats.The Problem
As detailed in issue #859, there were three core problems:
--formatflag did not distinguish between compression and decompression capabilities.These issues stemmed from the lack of a single source of truth for format information.
The Solution
This PR implements the suggestions from the issue by making format information a central, authoritative part of the application.
Central Format Registry (
src/formats.rs)A new module,
src/formats.rs, now acts as the single source of truth. It defines every supported format, its extensions and aliases, its role (archive vs. compressor), and its capabilities (compress/decompress). This eliminates hardcoded lists and prevents future drift between documentation, hints, and application logic.New
list-formatsSubcommandA new subcommand
ouch list-formats(with aliasesformatsandsupport) has been added. It prints a detailed, beautifully formatted table of all supported formats and their capabilities, generated directly from the new registry.Smarter, Context-Aware Hints
Error messages are now much more helpful. The logic distinguishes between two types of errors:
ouch compress file output), the hint is highly specific to the command being run, showing only the formats that support compression.--format(e.g.,ouch decompress file --format asd), the tool assumes the user might be confused about general capabilities, so it provides broader guidance by showing two separate, clearly labeled lists for all supported compression and decompression formats.Code Refactoring
The
extension.rsanderror.rsmodules have been refactored to consume information from the newformats.rsregistry, ensuring consistency across the entire application.Benefits of the New
list-formatsCommandThe new
ouch list-formatscommand provides a comprehensive and easy-to-understand overview of all supported formats, empowering users to understand and useouchmore effectively.Clarifies Format Roles: The
ROLEcolumn immediately teaches the user the crucial difference between anarchive(a container for multiple files, liketarorzip) and acompressor(an algorithm that works on a single stream of data). This helps users understand why they needtarto compress a directory.Shows Explicit Capabilities: The
COMPRESSandDECOMPRESScolumns remove all guesswork. Users can see at a glance that, for example,ouchcan decompress.rarfiles but cannot create them, or that.lzmadecompression is supported but compression is not.Demystifies Shorthands: The separate shorthands table clearly shows how convenient aliases like
tgzexpand to their fulltar.gzequivalent, distinguishing them from single-format extensions.New CLI Output
Here are some examples of the new and improved output.
1. The
list-formatscommand output:Note: The layout is responsive. The capabilities and shorthands tables will appear side-by-side on wide terminals, or stacked vertically on narrow ones.
2. Context-aware hint for a missing compression format:
3. General hint for an invalid format provided via flag: