@@ -17,72 +17,75 @@ limitations under the License.
1717package cmd
1818
1919import (
20- "fmt"
21- "io"
22- "path/filepath"
23- "runtime"
24- "time"
20+ "fmt"
21+ "io"
22+ "path/filepath"
23+ "runtime"
24+ "time"
2525
26- "github.com/linuxsuren/api-testing/pkg/downloader"
27- "github.com/spf13/cobra"
26+ "github.com/linuxsuren/api-testing/pkg/downloader"
27+ "github.com/spf13/cobra"
2828)
2929
3030type extensionOption struct {
31- ociDownloader downloader.PlatformAwareOCIDownloader
32- output string
33- registry string
34- tag string
35- os string
36- arch string
37- timeout time.Duration
38- imagePrefix string
31+ ociDownloader downloader.PlatformAwareOCIDownloader
32+ output string
33+ registry string
34+ kind string
35+ tag string
36+ os string
37+ arch string
38+ timeout time.Duration
39+ imagePrefix string
3940}
4041
4142func createExtensionCommand (ociDownloader downloader.PlatformAwareOCIDownloader ) (c * cobra.Command ) {
42- opt := & extensionOption {
43- ociDownloader : ociDownloader ,
44- }
45- c = & cobra.Command {
46- Use : "extension" ,
47- Short : "Download extension binary files" ,
48- Long : "Download the store extension files" ,
49- Args : cobra .MinimumNArgs (1 ),
50- RunE : opt .runE ,
51- }
52- flags := c .Flags ()
53- flags .StringVarP (& opt .output , "output" , "" , "." , "The target directory" )
54- flags .StringVarP (& opt .tag , "tag" , "" , "" , "The extension image tag, try to find the latest one if this is empty" )
55- flags .StringVarP (& opt .registry , "registry" , "" , "" , "The target extension image registry, supported: docker.io, ghcr.io" )
56- flags .StringVarP (& opt .os , "os" , "" , runtime .GOOS , "The OS" )
57- flags .StringVarP (& opt .arch , "arch" , "" , runtime .GOARCH , "The architecture" )
58- flags .DurationVarP (& opt .timeout , "timeout" , "" , time .Minute , "The timeout of downloading" )
59- flags .StringVarP (& opt .imagePrefix , "image-prefix" , "" , "linuxsuren" , "The prefix for the image address" )
60- return
43+ opt := & extensionOption {
44+ ociDownloader : ociDownloader ,
45+ }
46+ c = & cobra.Command {
47+ Use : "extension" ,
48+ Short : "Download extension binary files" ,
49+ Long : "Download the store extension files" ,
50+ Args : cobra .MinimumNArgs (1 ),
51+ RunE : opt .runE ,
52+ }
53+ flags := c .Flags ()
54+ flags .StringVarP (& opt .output , "output" , "" , "." , "The target directory" )
55+ flags .StringVarP (& opt .tag , "tag" , "" , "" , "The extension image tag, try to find the latest one if this is empty" )
56+ flags .StringVarP (& opt .registry , "registry" , "" , "" , "The target extension image registry, supported: docker.io, ghcr.io" )
57+ flags .StringVarP (& opt .kind , "kind" , "" , "store" , "The extension kind" )
58+ flags .StringVarP (& opt .os , "os" , "" , runtime .GOOS , "The OS" )
59+ flags .StringVarP (& opt .arch , "arch" , "" , runtime .GOARCH , "The architecture" )
60+ flags .DurationVarP (& opt .timeout , "timeout" , "" , time .Minute , "The timeout of downloading" )
61+ flags .StringVarP (& opt .imagePrefix , "image-prefix" , "" , "linuxsuren" , "The prefix for the image address" )
62+ return
6163}
6264
6365func (o * extensionOption ) runE (cmd * cobra.Command , args []string ) (err error ) {
64- o .ociDownloader .WithOS (o .os )
65- o .ociDownloader .WithArch (o .arch )
66- o .ociDownloader .WithRegistry (o .registry )
67- o .ociDownloader .WithImagePrefix (o .imagePrefix )
68- o .ociDownloader .WithTimeout (o .timeout )
69- o .ociDownloader .WithContext (cmd .Context ())
66+ o .ociDownloader .WithOS (o .os )
67+ o .ociDownloader .WithArch (o .arch )
68+ o .ociDownloader .WithRegistry (o .registry )
69+ o .ociDownloader .WithImagePrefix (o .imagePrefix )
70+ o .ociDownloader .WithTimeout (o .timeout )
71+ o .ociDownloader .WithKind (o .kind )
72+ o .ociDownloader .WithContext (cmd .Context ())
7073
71- for _ , arg := range args {
72- var reader io.Reader
73- if reader , err = o .ociDownloader .Download (arg , o .tag , "" ); err != nil {
74- return
75- } else if reader == nil {
76- err = fmt .Errorf ("cannot find %s" , arg )
77- return
78- }
79- extFile := o .ociDownloader .GetTargetFile ()
80- cmd .Println ("found target file" , extFile )
74+ for _ , arg := range args {
75+ var reader io.Reader
76+ if reader , err = o .ociDownloader .Download (arg , o .tag , "" ); err != nil {
77+ return
78+ } else if reader == nil {
79+ err = fmt .Errorf ("cannot find %s" , arg )
80+ return
81+ }
82+ extFile := o .ociDownloader .GetTargetFile ()
83+ cmd .Println ("found target file" , extFile )
8184
82- targetFile := filepath .Base (extFile )
83- if err = downloader .WriteTo (reader , o .output , targetFile ); err == nil {
84- cmd .Println ("downloaded" , targetFile )
85- }
86- }
87- return
85+ targetFile := filepath .Base (extFile )
86+ if err = downloader .WriteTo (reader , o .output , targetFile ); err == nil {
87+ cmd .Println ("downloaded" , targetFile )
88+ }
89+ }
90+ return
8891}
0 commit comments