Add `--format` flag
Problem
Currently, we don't have control of what extensions should be used in compression or decompression, we rely on automatic extension detection.
Using archive.tar.gz.xz as an example, you might want to decompress it into:
archive.tar.gz, without the .xz part, or
archive.tar, without the .gz.xz part.
That is, decompress it partially, or just decompress a file without extensions.
Workaround
Decompress and compress it again.
ouch decompress archive.tar.gz.xz -o result
cd result
ouch compress * .* archive.tar
Note that the shell expansion .* is necessary in case you have any hidden files.
New solution
--format flag that overwrites the automatic format detection system.
ouch compress file.tar file.tar.xz --format xz
ouch decompress secret_file --format tar.gz
We already have detection on partial compression:
ouch compress file.tar file.tar.xz
Ouch detects it should only partially compress the .xz part, and triggers it, I think this behavior is useful but can be triggered by accident.
We should leave this detection only as a warning to tell the users that if they want to partially compress, they should use the --format flag.
+1 i wanted to decompress a zstd initrd but couldn't since it has no extension
file -z $(chase ./result/system/initrd)
/nix/store/gipn2hp41a70bdrzbkcy4dgqxp789z03-initrd-linux-5.10.81/initrd: ASCII cpio archive (SVR4 with no CRC) (Zstandard compressed data (v0.8+), Dictionary ID: None)
@Artturin can you try with master branch? It should infer the extension
I will be attempting to solve this ~~now~~.
@Artturin can you try with master branch? It should infer the extension
rev 308b8f7e906c57d8da334ae6395aa15ecbdfb2d8
./result/bin/ouch decompress $(chase /run/current-system/initrd)
[ERROR] Cannot decompress files without extensions
- Files without supported extensions: /nix/store/c2xv04iimpji7hwd18qnzhcpf1fx2isx-initrd-linux-5.10.90/initrd
- Decompression formats are detected automatically by the file extension
hint: Provide a file with a supported extension:
hint: ouch decompress example.tar.gz
hint:
hint: Or overwrite this option with the '--format' flag:
hint: ouch decompress /nix/store/c2xv04iimpji7hwd18qnzhcpf1fx2isx-initrd-linux-5.10.90/initrd --format tar.gz
--format gives
./result/bin/ouch decompress $(chase /run/current-system/initrd) --format zst
error: Found argument '--format' which wasn't expected, or isn't valid in this context
If you tried to supply `--format` as a value rather than a flag, use `-- --format`
USAGE:
ouch decompress [OPTIONS] <FILES>...
For more information try --help
--format gives
You're right, I had --format unimplemented because I had to stay a little bit away from Ouch.
This is totally broken and needs to be addressed.
this will require rework on the error handling part, in a medium sized PR, so I'm removing it from the 0.4 milestone just so that we can make the next release
https://github.com/ouch-org/ouch/pull/341