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-formats
subcommand. 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:
--format
flag 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-formats
SubcommandA new subcommand
ouch list-formats
(with aliasesformats
andsupport
) 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.rs
anderror.rs
modules have been refactored to consume information from the newformats.rs
registry, ensuring consistency across the entire application.Benefits of the New
list-formats
CommandThe new
ouch list-formats
command provides a comprehensive and easy-to-understand overview of all supported formats, empowering users to understand and useouch
more effectively.Clarifies Format Roles: The
ROLE
column immediately teaches the user the crucial difference between anarchive
(a container for multiple files, liketar
orzip
) and acompressor
(an algorithm that works on a single stream of data). This helps users understand why they needtar
to compress a directory.Shows Explicit Capabilities: The
COMPRESS
andDECOMPRESS
columns remove all guesswork. Users can see at a glance that, for example,ouch
can decompress.rar
files but cannot create them, or that.lzma
decompression is supported but compression is not.Demystifies Shorthands: The separate shorthands table clearly shows how convenient aliases like
tgz
expand to their fulltar.gz
equivalent, distinguishing them from single-format extensions.New CLI Output
Here are some examples of the new and improved output.
1. The
list-formats
command 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: