@@ -23,23 +23,59 @@ import (
2323 "path/filepath"
2424 "strings"
2525
26+ "github.com/pkg/errors"
27+ "github.com/sirupsen/logrus"
28+
2629 "github.com/compose-spec/compose-go/consts"
2730 "github.com/compose-spec/compose-go/dotenv"
2831 "github.com/compose-spec/compose-go/errdefs"
2932 "github.com/compose-spec/compose-go/loader"
3033 "github.com/compose-spec/compose-go/types"
3134 "github.com/compose-spec/compose-go/utils"
32- "github.com/pkg/errors"
33- "github.com/sirupsen/logrus"
3435)
3536
36- // ProjectOptions groups the command line options recommended for a Compose implementation
37+ // ProjectOptions provides common configuration for loading a project.
3738type ProjectOptions struct {
38- Name string
39- WorkingDir string
39+ // Name is a valid Compose project name to be used or empty.
40+ //
41+ // If empty, the project loader will automatically infer a reasonable
42+ // project name if possible.
43+ Name string
44+
45+ // WorkingDir is a file path to use as the project directory or empty.
46+ //
47+ // If empty, the project loader will automatically infer a reasonable
48+ // working directory if possible.
49+ WorkingDir string
50+
51+ // ConfigPaths are file paths to one or more Compose files.
52+ //
53+ // These are applied in order by the loader following the merge logic
54+ // as described in the spec.
55+ //
56+ // The first entry is required and is the primary Compose file.
57+ // For convenience, WithConfigFileEnv and WithDefaultConfigPath
58+ // are provided to populate this in a predictable manner.
4059 ConfigPaths []string
60+
61+ // Environment are additional environment variables to make available
62+ // for interpolation.
63+ //
64+ // NOTE: For security, the loader does not automatically expose any
65+ // process environment variables. For convenience, WithOsEnv can be
66+ // used if appropriate.
4167 Environment map [string ]string
42- EnvFiles []string
68+
69+ // EnvFiles are file paths to ".env" files with additional environment
70+ // variable data.
71+ //
72+ // These are loaded in-order, so it is possible to override variables or
73+ // in subsequent files.
74+ //
75+ // This field is optional, but any file paths that are included here must
76+ // exist or an error will be returned during load.
77+ EnvFiles []string
78+
4379 loadOptions []func (* loader.Options )
4480}
4581
@@ -63,9 +99,15 @@ func NewProjectOptions(configs []string, opts ...ProjectOptionsFn) (*ProjectOpti
6399// WithName defines ProjectOptions' name
64100func WithName (name string ) ProjectOptionsFn {
65101 return func (o * ProjectOptions ) error {
66- normalized := loader .NormalizeProjectName (name )
67- if err := loader .CheckOriginalProjectNameIsNormalized (name , normalized ); err != nil {
68- return err
102+ // a project (once loaded) cannot have an empty name
103+ // however, on the options object, the name is optional: if unset,
104+ // a name will be inferred by the loader, so it's legal to set the
105+ // name to an empty string here
106+ if name != "" {
107+ normalized := loader .NormalizeProjectName (name )
108+ if err := loader .CheckOriginalProjectNameIsNormalized (name , normalized ); err != nil {
109+ return err
110+ }
69111 }
70112 o .Name = name
71113 return nil
0 commit comments