mirror of
https://github.com/apricote/hcloud-upload-image.git
synced 2026-01-13 13:21:01 +00:00
parent
921d688fd4
commit
37ebbce517
4 changed files with 24 additions and 6 deletions
|
|
@ -121,10 +121,10 @@ func init() {
|
||||||
uploadCmd.MarkFlagsMutuallyExclusive(uploadFlagImageURL, uploadFlagImagePath)
|
uploadCmd.MarkFlagsMutuallyExclusive(uploadFlagImageURL, uploadFlagImagePath)
|
||||||
uploadCmd.MarkFlagsOneRequired(uploadFlagImageURL, uploadFlagImagePath)
|
uploadCmd.MarkFlagsOneRequired(uploadFlagImageURL, uploadFlagImagePath)
|
||||||
|
|
||||||
uploadCmd.Flags().String(uploadFlagCompression, "", "Type of compression that was used on the disk image [choices: bz2, xz]")
|
uploadCmd.Flags().String(uploadFlagCompression, "", "Type of compression that was used on the disk image [choices: bz2, xz, zstd]")
|
||||||
_ = uploadCmd.RegisterFlagCompletionFunc(
|
_ = uploadCmd.RegisterFlagCompletionFunc(
|
||||||
uploadFlagCompression,
|
uploadFlagCompression,
|
||||||
cobra.FixedCompletions([]string{string(hcloudimages.CompressionBZ2), string(hcloudimages.CompressionXZ)}, cobra.ShellCompDirectiveNoFileComp),
|
cobra.FixedCompletions([]string{string(hcloudimages.CompressionBZ2), string(hcloudimages.CompressionXZ), string(hcloudimages.CompressionZSTD)}, cobra.ShellCompDirectiveNoFileComp),
|
||||||
)
|
)
|
||||||
|
|
||||||
uploadCmd.Flags().String(uploadFlagFormat, "", "Format of the image. [choices: qcow2]")
|
uploadCmd.Flags().String(uploadFlagFormat, "", "Format of the image. [choices: qcow2]")
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ hcloud-upload-image upload (--image-path=<local-path> | --image-url=<url>) --arc
|
||||||
|
|
||||||
```
|
```
|
||||||
--architecture string CPU architecture of the disk image [choices: x86, arm]
|
--architecture string CPU architecture of the disk image [choices: x86, arm]
|
||||||
--compression string Type of compression that was used on the disk image [choices: bz2, xz]
|
--compression string Type of compression that was used on the disk image [choices: bz2, xz, zstd]
|
||||||
--description string Description for the resulting image
|
--description string Description for the resulting image
|
||||||
--format string Format of the image. [choices: qcow2]
|
--format string Format of the image. [choices: qcow2]
|
||||||
-h, --help help for upload
|
-h, --help help for upload
|
||||||
|
|
|
||||||
|
|
@ -104,9 +104,10 @@ const (
|
||||||
CompressionNone Compression = ""
|
CompressionNone Compression = ""
|
||||||
CompressionBZ2 Compression = "bz2"
|
CompressionBZ2 Compression = "bz2"
|
||||||
CompressionXZ Compression = "xz"
|
CompressionXZ Compression = "xz"
|
||||||
|
CompressionZSTD Compression = "zstd"
|
||||||
|
|
||||||
// Possible future additions:
|
// Possible future additions:
|
||||||
// zip,zstd
|
// zip
|
||||||
)
|
)
|
||||||
|
|
||||||
type Format string
|
type Format string
|
||||||
|
|
@ -524,6 +525,8 @@ func assembleCommand(options UploadOptions) (string, error) {
|
||||||
cmd += "bzip2 -cd | "
|
cmd += "bzip2 -cd | "
|
||||||
case CompressionXZ:
|
case CompressionXZ:
|
||||||
cmd += "xz -cd | "
|
cmd += "xz -cd | "
|
||||||
|
case CompressionZSTD:
|
||||||
|
cmd += "zstd -cd | "
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("unknown compression: %q", options.ImageCompression)
|
return "", fmt.Errorf("unknown compression: %q", options.ImageCompression)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,21 @@ func TestAssembleCommand(t *testing.T) {
|
||||||
},
|
},
|
||||||
want: "bash -c 'set -euo pipefail && wget --no-verbose -O - \"https://example.com/image.xz\" | xz -cd | dd of=/dev/sda bs=4M && sync'",
|
want: "bash -c 'set -euo pipefail && wget --no-verbose -O - \"https://example.com/image.xz\" | xz -cd | dd of=/dev/sda bs=4M && sync'",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "local zstd",
|
||||||
|
options: UploadOptions{
|
||||||
|
ImageCompression: CompressionZSTD,
|
||||||
|
},
|
||||||
|
want: "bash -c 'set -euo pipefail && zstd -cd | dd of=/dev/sda bs=4M && sync'",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "remote zstd",
|
||||||
|
options: UploadOptions{
|
||||||
|
ImageURL: mustParseURL("https://example.com/image.zst"),
|
||||||
|
ImageCompression: CompressionZSTD,
|
||||||
|
},
|
||||||
|
want: "bash -c 'set -euo pipefail && wget --no-verbose -O - \"https://example.com/image.zst\" | zstd -cd | dd of=/dev/sda bs=4M && sync'",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "local bz2",
|
name: "local bz2",
|
||||||
options: UploadOptions{
|
options: UploadOptions{
|
||||||
|
|
@ -59,9 +74,9 @@ func TestAssembleCommand(t *testing.T) {
|
||||||
name: "remote bz2",
|
name: "remote bz2",
|
||||||
options: UploadOptions{
|
options: UploadOptions{
|
||||||
ImageURL: mustParseURL("https://example.com/image.bz2"),
|
ImageURL: mustParseURL("https://example.com/image.bz2"),
|
||||||
ImageCompression: CompressionXZ,
|
ImageCompression: CompressionBZ2,
|
||||||
},
|
},
|
||||||
want: "bash -c 'set -euo pipefail && wget --no-verbose -O - \"https://example.com/image.bz2\" | xz -cd | dd of=/dev/sda bs=4M && sync'",
|
want: "bash -c 'set -euo pipefail && wget --no-verbose -O - \"https://example.com/image.bz2\" | bzip2 -cd | dd of=/dev/sda bs=4M && sync'",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "local qcow2",
|
name: "local qcow2",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue