NewAPIClientFromFlags creates a new APIClient from command line flags
(opts *cliflags.ClientOptions, configFile *configfile.ConfigFile)
| 282 | |
| 283 | // NewAPIClientFromFlags creates a new APIClient from command line flags |
| 284 | func NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile.ConfigFile) (client.APIClient, error) { |
| 285 | if opts.Context != "" && len(opts.Hosts) > 0 { |
| 286 | return nil, errors.New("conflicting options: cannot specify both --host and --context") |
| 287 | } |
| 288 | |
| 289 | storeConfig := DefaultContextStoreConfig() |
| 290 | contextStore := &ContextStoreWithDefault{ |
| 291 | Store: store.New(config.ContextStoreDir(), storeConfig), |
| 292 | Resolver: func() (*DefaultContext, error) { |
| 293 | return resolveDefaultContext(opts, storeConfig) |
| 294 | }, |
| 295 | } |
| 296 | endpoint, err := resolveDockerEndpoint(contextStore, resolveContextName(opts, configFile)) |
| 297 | if err != nil { |
| 298 | return nil, fmt.Errorf("unable to resolve docker endpoint: %w", err) |
| 299 | } |
| 300 | return newAPIClientFromEndpoint(endpoint, configFile, client.WithUserAgent(UserAgent())) |
| 301 | } |
| 302 | |
| 303 | func newAPIClientFromEndpoint(ep docker.Endpoint, configFile *configfile.ConfigFile, extraOpts ...client.Opt) (client.APIClient, error) { |
| 304 | opts, err := ep.ClientOpts() |
searching dependent graphs…