mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update compose-go to v2.0.0-rc.8
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
83
vendor/github.com/compose-spec/compose-go/v2/cli/options.go
generated
vendored
83
vendor/github.com/compose-spec/compose-go/v2/cli/options.go
generated
vendored
@ -37,8 +37,6 @@ import (
|
||||
|
||||
// ProjectOptions provides common configuration for loading a project.
|
||||
type ProjectOptions struct {
|
||||
ctx context.Context
|
||||
|
||||
// Name is a valid Compose project name to be used or empty.
|
||||
//
|
||||
// If empty, the project loader will automatically infer a reasonable
|
||||
@ -80,6 +78,10 @@ type ProjectOptions struct {
|
||||
EnvFiles []string
|
||||
|
||||
loadOptions []func(*loader.Options)
|
||||
|
||||
// Callbacks to retrieve metadata information during parse defined before
|
||||
// creating the project
|
||||
Listeners []loader.Listener
|
||||
}
|
||||
|
||||
type ProjectOptionsFn func(*ProjectOptions) error
|
||||
@ -89,6 +91,7 @@ func NewProjectOptions(configs []string, opts ...ProjectOptionsFn) (*ProjectOpti
|
||||
options := &ProjectOptions{
|
||||
ConfigPaths: configs,
|
||||
Environment: map[string]string{},
|
||||
Listeners: []loader.Listener{},
|
||||
}
|
||||
for _, o := range opts {
|
||||
err := o(options)
|
||||
@ -334,14 +337,6 @@ func WithResolvedPaths(resolve bool) ProjectOptionsFn {
|
||||
}
|
||||
}
|
||||
|
||||
// WithContext sets the context used to load model and resources
|
||||
func WithContext(ctx context.Context) ProjectOptionsFn {
|
||||
return func(o *ProjectOptions) error {
|
||||
o.ctx = ctx
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithResourceLoader register support for ResourceLoader to manage remote resources
|
||||
func WithResourceLoader(r loader.ResourceLoader) ProjectOptionsFn {
|
||||
return func(o *ProjectOptions) error {
|
||||
@ -352,6 +347,24 @@ func WithResourceLoader(r loader.ResourceLoader) ProjectOptionsFn {
|
||||
}
|
||||
}
|
||||
|
||||
// WithExtension register a know extension `x-*` with the go struct type to decode into
|
||||
func WithExtension(name string, typ any) ProjectOptionsFn {
|
||||
return func(o *ProjectOptions) error {
|
||||
o.loadOptions = append(o.loadOptions, func(options *loader.Options) {
|
||||
if options.KnownExtensions == nil {
|
||||
options.KnownExtensions = map[string]any{}
|
||||
}
|
||||
options.KnownExtensions[name] = typ
|
||||
})
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Append listener to event
|
||||
func (o *ProjectOptions) WithListeners(listeners ...loader.Listener) {
|
||||
o.Listeners = append(o.Listeners, listeners...)
|
||||
}
|
||||
|
||||
// WithoutEnvironmentResolution disable environment resolution
|
||||
func WithoutEnvironmentResolution(o *ProjectOptions) error {
|
||||
o.loadOptions = append(o.loadOptions, func(options *loader.Options) {
|
||||
@ -368,7 +381,7 @@ var DefaultOverrideFileNames = []string{"compose.override.yml", "compose.overrid
|
||||
|
||||
func (o ProjectOptions) GetWorkingDir() (string, error) {
|
||||
if o.WorkingDir != "" {
|
||||
return o.WorkingDir, nil
|
||||
return filepath.Abs(o.WorkingDir)
|
||||
}
|
||||
for _, path := range o.ConfigPaths {
|
||||
if path != "-" {
|
||||
@ -382,9 +395,8 @@ func (o ProjectOptions) GetWorkingDir() (string, error) {
|
||||
return os.Getwd()
|
||||
}
|
||||
|
||||
// ProjectFromOptions load a compose project based on command line options
|
||||
func ProjectFromOptions(options *ProjectOptions) (*types.Project, error) {
|
||||
configPaths, err := getConfigPathsFromOptions(options)
|
||||
func (o ProjectOptions) GeConfigFiles() ([]types.ConfigFile, error) {
|
||||
configPaths, err := o.getConfigPaths()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -412,24 +424,25 @@ func ProjectFromOptions(options *ProjectOptions) (*types.Project, error) {
|
||||
Content: b,
|
||||
})
|
||||
}
|
||||
return configs, err
|
||||
}
|
||||
|
||||
// ProjectFromOptions load a compose project based on command line options
|
||||
func ProjectFromOptions(ctx context.Context, options *ProjectOptions) (*types.Project, error) {
|
||||
configs, err := options.GeConfigFiles()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
workingDir, err := options.GetWorkingDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
absWorkingDir, err := filepath.Abs(workingDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
options.loadOptions = append(options.loadOptions,
|
||||
withNamePrecedenceLoad(absWorkingDir, options),
|
||||
withConvertWindowsPaths(options))
|
||||
|
||||
ctx := options.ctx
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
withNamePrecedenceLoad(workingDir, options),
|
||||
withConvertWindowsPaths(options),
|
||||
withListeners(options))
|
||||
|
||||
project, err := loader.LoadWithContext(ctx, types.ConfigDetails{
|
||||
ConfigFiles: configs,
|
||||
@ -440,7 +453,10 @@ func ProjectFromOptions(options *ProjectOptions) (*types.Project, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
project.ComposeFiles = configPaths
|
||||
for _, config := range configs {
|
||||
project.ComposeFiles = append(project.ComposeFiles, config.Filename)
|
||||
}
|
||||
|
||||
return project, nil
|
||||
}
|
||||
|
||||
@ -467,10 +483,17 @@ func withConvertWindowsPaths(options *ProjectOptions) func(*loader.Options) {
|
||||
}
|
||||
}
|
||||
|
||||
// getConfigPathsFromOptions retrieves the config files for project based on project options
|
||||
func getConfigPathsFromOptions(options *ProjectOptions) ([]string, error) {
|
||||
if len(options.ConfigPaths) != 0 {
|
||||
return absolutePaths(options.ConfigPaths)
|
||||
// save listeners from ProjectOptions (compose) to loader.Options
|
||||
func withListeners(options *ProjectOptions) func(*loader.Options) {
|
||||
return func(opts *loader.Options) {
|
||||
opts.Listeners = append(opts.Listeners, options.Listeners...)
|
||||
}
|
||||
}
|
||||
|
||||
// getConfigPaths retrieves the config files for project based on project options
|
||||
func (o *ProjectOptions) getConfigPaths() ([]string, error) {
|
||||
if len(o.ConfigPaths) != 0 {
|
||||
return absolutePaths(o.ConfigPaths)
|
||||
}
|
||||
return nil, fmt.Errorf("no configuration file provided: %w", errdefs.ErrNotFound)
|
||||
}
|
||||
|
Reference in New Issue
Block a user