@@ -23,23 +23,59 @@ import (
23
23
"path/filepath"
24
24
"strings"
25
25
26
+ "github.com/pkg/errors"
27
+ "github.com/sirupsen/logrus"
28
+
26
29
"github.com/compose-spec/compose-go/consts"
27
30
"github.com/compose-spec/compose-go/dotenv"
28
31
"github.com/compose-spec/compose-go/errdefs"
29
32
"github.com/compose-spec/compose-go/loader"
30
33
"github.com/compose-spec/compose-go/types"
31
34
"github.com/compose-spec/compose-go/utils"
32
- "github.com/pkg/errors"
33
- "github.com/sirupsen/logrus"
34
35
)
35
36
36
- // ProjectOptions groups the command line options recommended for a Compose implementation
37
+ // ProjectOptions provides common configuration for loading a project.
37
38
type 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.
40
59
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.
41
67
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
+
43
79
loadOptions []func (* loader.Options )
44
80
}
45
81
@@ -63,9 +99,15 @@ func NewProjectOptions(configs []string, opts ...ProjectOptionsFn) (*ProjectOpti
63
99
// WithName defines ProjectOptions' name
64
100
func WithName (name string ) ProjectOptionsFn {
65
101
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
+ }
69
111
}
70
112
o .Name = name
71
113
return nil
0 commit comments