@@ -17,75 +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- kind string
35- tag string
36- os string
37- arch string
38- timeout time.Duration
39- 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
4040}
4141
4242func createExtensionCommand (ociDownloader downloader.PlatformAwareOCIDownloader ) (c * cobra.Command ) {
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
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
6363}
6464
6565func (o * extensionOption ) runE (cmd * cobra.Command , args []string ) (err error ) {
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 ())
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 ())
7373
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 )
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 )
8484
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
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
9191}
0 commit comments