feat(build): accept archive format aliases

This commit is contained in:
Virgil 2026-04-01 20:02:36 +00:00
parent e882b3a6b1
commit 891b06eac8
2 changed files with 11 additions and 3 deletions

View file

@ -36,9 +36,9 @@ const (
// format, err := build.ParseArchiveFormat("zip") // → build.ArchiveFormatZip
func ParseArchiveFormat(value string) (ArchiveFormat, error) {
switch core.Trim(strings.ToLower(value)) {
case "", "gz", "gzip", "tar.gz":
case "", "gz", "gzip", "tgz", "tar.gz", "tar-gz":
return ArchiveFormatGzip, nil
case "xz", "tar.xz":
case "xz", "txz", "tar.xz", "tar-xz":
return ArchiveFormatXZ, nil
case "zip":
return ArchiveFormatZip, nil

View file

@ -205,7 +205,7 @@ func TestArchive_ParseArchiveFormat_Good(t *testing.T) {
})
t.Run("accepts xz aliases", func(t *testing.T) {
for _, input := range []string{"xz", "tar.xz"} {
for _, input := range []string{"xz", "txz", "tar.xz", "tar-xz"} {
format, err := ParseArchiveFormat(input)
require.NoError(t, err)
assert.Equal(t, ArchiveFormatXZ, format)
@ -218,6 +218,14 @@ func TestArchive_ParseArchiveFormat_Good(t *testing.T) {
assert.Equal(t, ArchiveFormatZip, format)
})
t.Run("accepts gzip aliases", func(t *testing.T) {
for _, input := range []string{"gz", "gzip", "tgz", "tar.gz", "tar-gz"} {
format, err := ParseArchiveFormat(input)
require.NoError(t, err)
assert.Equal(t, ArchiveFormatGzip, format)
}
})
t.Run("rejects unsupported formats", func(t *testing.T) {
format, err := ParseArchiveFormat("bzip2")
assert.Error(t, err)