6
6
"path"
7
7
"path/filepath"
8
8
"runtime"
9
+ "strings"
9
10
10
11
"github.com/crc-org/crc/pkg/crc/constants"
11
12
"github.com/crc-org/crc/pkg/crc/logging"
@@ -21,13 +22,23 @@ import (
21
22
var (
22
23
goos string
23
24
cacheDir string
25
+ components []string
24
26
noDownload bool
25
27
)
26
28
29
+ const (
30
+ vfkitDriver = "vfkit-driver"
31
+ vfkitEntitlement = "vfkit-entitlement"
32
+ libvirtDriver = "libvirt-driver"
33
+ adminHelper = "admin-helper"
34
+ tray = "tray"
35
+ )
36
+
27
37
func init () {
28
38
embedCmd .Flags ().StringVar (& goos , "goos" , runtime .GOOS , "Target platform (darwin, linux or windows)" )
29
39
embedCmd .Flags ().StringVar (& cacheDir , "cache-dir" , "" , "Destination directory for the downloaded files" )
30
40
embedCmd .Flags ().BoolVar (& noDownload , "no-download" , false , "Only embed files, don't download" )
41
+ embedCmd .Flags ().StringSliceVar (& components , "components" , []string {}, fmt .Sprintf ("List of component(s) to download (%s)" , strings .Join (getAllComponentNames (goos ), ", " )))
31
42
rootCmd .AddCommand (embedCmd )
32
43
}
33
44
@@ -55,7 +66,7 @@ func runEmbed(args []string) {
55
66
if noDownload {
56
67
embedFileList = getEmbedFileList (goos , cacheDir )
57
68
} else {
58
- embedFileList , err = downloadDataFiles (goos , cacheDir )
69
+ embedFileList , err = downloadDataFiles (goos , components , cacheDir )
59
70
if err != nil {
60
71
logging .Fatalf ("Failed to download data files: %v" , err )
61
72
}
@@ -95,20 +106,20 @@ type remoteFileInfo struct {
95
106
}
96
107
97
108
var (
98
- dataFileUrls = map [string ][ ]remoteFileInfo {
109
+ dataFileUrls = map [string ]map [ string ]remoteFileInfo {
99
110
"darwin" : {
100
- {vfkit .VfkitDownloadURL , 0755 },
101
- {vfkit .VfkitEntitlementsURL , 0644 },
102
- {constants .GetCRCMacTrayDownloadURL (), 0644 },
103
- {constants .GetAdminHelperURLForOs ("darwin" ), 0755 },
111
+ vfkitDriver : {vfkit .VfkitDownloadURL , 0755 },
112
+ vfkitEntitlement : {vfkit .VfkitEntitlementsURL , 0644 },
113
+ tray : {constants .GetCRCMacTrayDownloadURL (), 0644 },
114
+ adminHelper : {constants .GetAdminHelperURLForOs ("darwin" ), 0755 },
104
115
},
105
116
"linux" : {
106
- {libvirt .MachineDriverDownloadURL , 0755 },
107
- {constants .GetAdminHelperURLForOs ("linux" ), 0755 },
117
+ libvirtDriver : {libvirt .MachineDriverDownloadURL , 0755 },
118
+ adminHelper : {constants .GetAdminHelperURLForOs ("linux" ), 0755 },
108
119
},
109
120
"windows" : {
110
- {constants .GetAdminHelperURLForOs ("windows" ), 0755 },
111
- {constants .GetCRCWindowsTrayDownloadURL (), 0644 },
121
+ adminHelper : {constants .GetAdminHelperURLForOs ("windows" ), 0755 },
122
+ tray : {constants .GetCRCWindowsTrayDownloadURL (), 0644 },
112
123
},
113
124
}
114
125
)
@@ -124,16 +135,44 @@ func getEmbedFileList(goos string, destDir string) []string {
124
135
return fileList
125
136
}
126
137
127
- func downloadDataFiles (goos string , destDir string ) ([]string , error ) {
138
+ func getAllComponentNames (goos string ) []string {
139
+ var components []string
140
+ for component := range dataFileUrls [goos ] {
141
+ components = append (components , component )
142
+ }
143
+ return components
144
+ }
145
+
146
+ func shouldDownload (components []string , component string ) bool {
147
+ if len (components ) == 0 {
148
+ return true
149
+ }
150
+ for _ , v := range components {
151
+ if v == component {
152
+ return true
153
+ }
154
+ }
155
+ return false
156
+ }
157
+
158
+ func downloadDataFiles (goos string , components []string , destDir string ) ([]string , error ) {
128
159
downloadedFiles := []string {}
129
160
downloads := dataFileUrls [goos ]
130
- for _ , dl := range downloads {
161
+
162
+ for componentName , dl := range downloads {
163
+ if ! shouldDownload (components , componentName ) {
164
+ continue
165
+ }
131
166
filename , err := download .Download (dl .url , destDir , dl .permissions , nil )
132
167
if err != nil {
133
168
return nil , err
134
169
}
135
170
downloadedFiles = append (downloadedFiles , filename )
136
171
}
137
172
173
+ if len (components ) != 0 && len (components ) != len (downloadedFiles ) {
174
+ logging .Warnf ("invalid components requested, supported components are: %s" , strings .Join (getAllComponentNames (goos ), ", " ))
175
+ }
176
+
138
177
return downloadedFiles , nil
139
178
}
0 commit comments