mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
create: improve interface when attempting to create docker driver
Previously, the help information for buildx indicated that users could create a new instance of the docker driver - which is explicitly something we don't support, driver of this form are automatically derived from the available list of docker contexts. This patch ensures that don't have AllowsInstance set will not appear in the help text, and additionally provide a new more specific error message instead of the generic "failed to find driver". This should help point users in the correct direction. Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
@ -92,16 +92,16 @@ func GetDefaultFactory(ctx context.Context, ep string, c dockerclient.APIClient,
|
||||
return dd[0].f, nil
|
||||
}
|
||||
|
||||
func GetFactory(name string, instanceRequired bool) Factory {
|
||||
func GetFactory(name string, instanceRequired bool) (Factory, error) {
|
||||
for _, f := range drivers {
|
||||
if instanceRequired && !f.AllowsInstances() {
|
||||
continue
|
||||
}
|
||||
if f.Name() == name {
|
||||
return f
|
||||
if instanceRequired && !f.AllowsInstances() {
|
||||
return nil, errors.Errorf("additional instances of driver %q cannot be created", name)
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return nil, errors.Errorf("failed to find driver %q", name)
|
||||
}
|
||||
|
||||
func GetDriver(ctx context.Context, name string, f Factory, endpointAddr string, api dockerclient.APIClient, auth Auth, kcc KubeClientConfig, flags []string, files map[string][]byte, do map[string]string, platforms []specs.Platform, contextPathHash string) (Driver, error) {
|
||||
@ -131,9 +131,12 @@ func GetDriver(ctx context.Context, name string, f Factory, endpointAddr string,
|
||||
return &cachedDriver{Driver: d}, nil
|
||||
}
|
||||
|
||||
func GetFactories() []Factory {
|
||||
func GetFactories(instanceRequired bool) []Factory {
|
||||
ds := make([]Factory, 0, len(drivers))
|
||||
for _, d := range drivers {
|
||||
if instanceRequired && !d.AllowsInstances() {
|
||||
continue
|
||||
}
|
||||
ds = append(ds, d)
|
||||
}
|
||||
sort.Slice(ds, func(i, j int) bool {
|
||||
|
Reference in New Issue
Block a user