Skip to content

Commit 691b97f

Browse files
author
matt
committed
feat: Add comic book aliases
Added aliases to extensions.rs and tests/mime.rs, updated snapshots to match, included changes in README
1 parent aeb27cc commit 691b97f

12 files changed

+31
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Categories Used:
2525
- Merge folders in decompression [\#798](https://github.com/ouch-org/ouch/pull/798) ([tommady](https://github.com/tommady))
2626
- Add `--no-smart-unpack` flag to decompression command to disable smart unpack [\#809](https://github.com/ouch-org/ouch/pull/809) ([talis-fb](https://github.com/talis-fb))
2727
- Provide Nushell completions (packages still need to install them) [\#827](https://github.com/ouch-org/ouch/pull/827) ([FrancescElies](https://github.com/FrancescElies))
28+
- Add aliases for comic book archives [\#835](https://github.com/ouch-org/ouch/pull/835) ([md9753](https://github.com/md9753))
2829
- Support `.lz` decompression [\#838](https://github.com/ouch-org/ouch/pull/838) ([zzzsyyy](https://github.com/zzzsyyy))
2930
- Support `.lzma` decompression (and fix `.lzma` being a wrong alias for `.xz`) [\#838](https://github.com/ouch-org/ouch/pull/838) ([zzzsyyy](https://github.com/zzzsyyy))
3031

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ Output:
128128
If you wish to exclude non-free code from your build, you can disable RAR support
129129
by building without the `unrar` feature.
130130

131-
`tar` aliases are also supported: `tgz`, `tbz`, `tbz2`, `tlz4`, `txz`, `tlzma`, `tsz`, `tzst`, `tlz`.
131+
Aliases for these formats are also supported:
132+
- `tar`: `tgz`, `tbz`, `tbz2`, `tlz4`, `txz`, `tlzma`, `tsz`, `tzst`, `tlz`, `cbt`
133+
- `zip`: `cbz`
134+
- `7z`: `cb7`
135+
- `rar`: `cbr`
132136

133137
Formats can be chained:
134138

src/extension.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ pub const SUPPORTED_EXTENSIONS: &[&str] = &[
2828
"br",
2929
];
3030

31-
pub const SUPPORTED_ALIASES: &[&str] = &["tgz", "tbz", "tlz4", "txz", "tlzma", "tsz", "tzst", "tlz"];
31+
pub const SUPPORTED_ALIASES: &[&str] = &[
32+
"tgz", "tbz", "tlz4", "txz", "tzlma", "tsz", "tzst", "tlz", "cbt", "cbz", "cb7", "cbr",
33+
];
3234

3335
#[cfg(not(feature = "unrar"))]
3436
pub const PRETTY_SUPPORTED_EXTENSIONS: &str = "tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, lz, sz, zst, 7z";
3537
#[cfg(feature = "unrar")]
3638
pub const PRETTY_SUPPORTED_EXTENSIONS: &str = "tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, lz, sz, zst, rar, 7z";
3739

38-
pub const PRETTY_SUPPORTED_ALIASES: &str = "tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz";
40+
pub const PRETTY_SUPPORTED_ALIASES: &str = "tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz, cbt, cbz, cb7, cbr";
3941

4042
/// A wrapper around `CompressionFormat` that allows combinations like `tgz`
4143
#[derive(Debug, Clone)]
@@ -94,15 +96,15 @@ pub enum CompressionFormat {
9496
Lzip,
9597
/// .sz
9698
Snappy,
97-
/// tar, tgz, tbz, tbz2, tbz3, txz, tlz4, tlzma, tsz, tzst
99+
/// tar, tgz, tbz, tbz2, tbz3, txz, tlz4, tlzma, tsz, tzst, cbt
98100
Tar,
99101
/// .zst
100102
Zstd,
101-
/// .zip
103+
/// .zip, .cbz
102104
Zip,
103-
/// .rar
105+
/// .rar, .cbr
104106
Rar,
105-
/// .7z
107+
/// .7z, .cb7
106108
SevenZip,
107109
/// .br
108110
Brotli,
@@ -121,7 +123,7 @@ impl CompressionFormat {
121123
fn to_extension(ext: &[u8]) -> Option<Extension> {
122124
Some(Extension::new(
123125
match ext {
124-
b"tar" => &[Tar],
126+
b"tar" | b"cbt" => &[Tar],
125127
b"tgz" => &[Tar, Gzip],
126128
b"tbz" | b"tbz2" => &[Tar, Bzip],
127129
b"tbz3" => &[Tar, Bzip3],
@@ -131,7 +133,7 @@ fn to_extension(ext: &[u8]) -> Option<Extension> {
131133
b"tlz" => &[Tar, Lzip],
132134
b"tsz" => &[Tar, Snappy],
133135
b"tzst" => &[Tar, Zstd],
134-
b"zip" => &[Zip],
136+
b"zip" | b"cbz" => &[Zip],
135137
b"bz" | b"bz2" => &[Bzip],
136138
b"bz3" => &[Bzip3],
137139
b"gz" => &[Gzip],
@@ -141,8 +143,8 @@ fn to_extension(ext: &[u8]) -> Option<Extension> {
141143
b"lz" => &[Lzip],
142144
b"sz" => &[Snappy],
143145
b"zst" => &[Zstd],
144-
b"rar" => &[Rar],
145-
b"7z" => &[SevenZip],
146+
b"rar" | b"cbr" => &[Rar],
147+
b"7z" | b"cb7" => &[SevenZip],
146148
b"br" => &[Brotli],
147149
_ => return None,
148150
},

tests/mime.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ fn sanity_check_through_mime() {
1717
write_random_content(test_file, &mut SmallRng::from_entropy());
1818

1919
let formats = [
20-
"7z", "tar", "zip", "tar.gz", "tgz", "tbz", "tbz2", "txz", "tzst", "tar.bz", "tar.bz2", "tar.xz", "tar.zst",
20+
"7z", "cb7", "tar", "cbt", "zip", "cbz", "tar.gz", "tgz", "tbz", "tbz2", "txz", "tzst", "tar.bz", "tar.bz2",
21+
"tar.xz", "tar.zst",
2122
];
2223

2324
let expected_mimes = [
2425
"application/x-7z-compressed",
26+
"application/x-7z-compressed",
27+
"application/x-tar",
2528
"application/x-tar",
2629
"application/zip",
30+
"application/zip",
2731
"application/gzip",
2832
"application/gzip",
2933
"application/x-bzip2",

tests/snapshots/ui__ui_test_err_decompress_missing_extension_with_rar-1.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ expression: "run_ouch(\"ouch decompress a\", dir)"
77
- Decompression formats are detected automatically from file extension
88

99
hint: Supported extensions are: tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, lz, sz, zst, rar, 7z
10-
hint: Supported aliases are: tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz
10+
hint: Supported aliases are: tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz, cbt, cbz, cb7, cbr
1111
hint:
1212
hint: Alternatively, you can pass an extension to the '--format' flag:
1313
hint: ouch decompress <TMP_DIR>/a --format tar.gz

tests/snapshots/ui__ui_test_err_decompress_missing_extension_with_rar-2.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ expression: "run_ouch(\"ouch decompress a b.unknown\", dir)"
88
- Decompression formats are detected automatically from file extension
99

1010
hint: Supported extensions are: tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, lz, sz, zst, rar, 7z
11-
hint: Supported aliases are: tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz
11+
hint: Supported aliases are: tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz, cbt, cbz, cb7, cbr

tests/snapshots/ui__ui_test_err_decompress_missing_extension_with_rar-3.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ expression: "run_ouch(\"ouch decompress b.unknown\", dir)"
77
- Decompression formats are detected automatically from file extension
88

99
hint: Supported extensions are: tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, lz, sz, zst, rar, 7z
10-
hint: Supported aliases are: tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz
10+
hint: Supported aliases are: tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz, cbt, cbz, cb7, cbr
1111
hint:
1212
hint: Alternatively, you can pass an extension to the '--format' flag:
1313
hint: ouch decompress <TMP_DIR>/b.unknown --format tar.gz

tests/snapshots/ui__ui_test_err_decompress_missing_extension_without_rar-1.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ expression: "run_ouch(\"ouch decompress a\", dir)"
77
- Decompression formats are detected automatically from file extension
88

99
hint: Supported extensions are: tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, lz, sz, zst, 7z
10-
hint: Supported aliases are: tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz
10+
hint: Supported aliases are: tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz, cbt, cbz, cb7, cbr
1111
hint:
1212
hint: Alternatively, you can pass an extension to the '--format' flag:
1313
hint: ouch decompress <TMP_DIR>/a --format tar.gz

tests/snapshots/ui__ui_test_err_format_flag_with_rar-1.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ expression: "run_ouch(\"ouch compress input output --format tar.gz.unknown\", di
66
- Unsupported extension 'unknown'
77

88
hint: Supported extensions are: tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, lz, sz, zst, rar, 7z
9-
hint: Supported aliases are: tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz
9+
hint: Supported aliases are: tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz, cbt, cbz, cb7, cbr
1010
hint:
1111
hint: Examples:
1212
hint: --format tar

tests/snapshots/ui__ui_test_err_format_flag_with_rar-2.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ expression: "run_ouch(\"ouch compress input output --format targz\", dir)"
66
- Unsupported extension 'targz'
77

88
hint: Supported extensions are: tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, lz, sz, zst, rar, 7z
9-
hint: Supported aliases are: tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz
9+
hint: Supported aliases are: tgz, tbz, tlz4, txz, tlzma, tsz, tzst, tlz, cbt, cbz, cb7, cbr
1010
hint:
1111
hint: Examples:
1212
hint: --format tar

0 commit comments

Comments
 (0)