Skip to content

Commit

Permalink
feat: upload xz compressed images (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
apricote authored May 9, 2024
1 parent fcea3e3 commit 1c943e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ func init() {
uploadCmd.MarkFlagsMutuallyExclusive(uploadFlagImageURL, uploadFlagImagePath)
uploadCmd.MarkFlagsOneRequired(uploadFlagImageURL, uploadFlagImagePath)

uploadCmd.Flags().String(uploadFlagCompression, "", "Type of compression that was used on the disk image [choices: bz2]")
uploadCmd.Flags().String(uploadFlagCompression, "", "Type of compression that was used on the disk image [choices: bz2, xz]")
_ = uploadCmd.RegisterFlagCompletionFunc(
uploadFlagCompression,
cobra.FixedCompletions([]string{string(hcloudimages.CompressionBZ2)}, cobra.ShellCompDirectiveNoFileComp),
cobra.FixedCompletions([]string{string(hcloudimages.CompressionBZ2), string(hcloudimages.CompressionXZ)}, cobra.ShellCompDirectiveNoFileComp),
)

uploadCmd.Flags().String(uploadFlagArchitecture, "", "CPU architecture of the disk image [choices: x86, arm]")
Expand Down
5 changes: 4 additions & 1 deletion hcloudimages/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ type Compression string
const (
CompressionNone Compression = ""
CompressionBZ2 Compression = "bz2"
CompressionXZ Compression = "xz"

// Possible future additions:
// zip,xz,zstd
// zip,zstd
)

// NewClient instantiates a new client. It requires a working [*hcloud.Client] to interact with the Hetzner Cloud API.
Expand Down Expand Up @@ -290,6 +291,8 @@ func (s *Client) Upload(ctx context.Context, options UploadOptions) (*hcloud.Ima
switch options.ImageCompression {
case CompressionBZ2:
cmd += "bzip2 -cd | "
case CompressionXZ:
cmd += "xz -cd | "
default:
return nil, fmt.Errorf("unknown compression: %q", options.ImageCompression)
}
Expand Down

0 comments on commit 1c943e4

Please sign in to comment.