Skip to content

Commit 89ef819

Browse files
tigerinusndeloof
authored andcommitted
update projectOptions to be public by renaming it to ProjectOptions
Signed-off-by: Tiger Wang <[email protected]>
1 parent b8bbdcd commit 89ef819

25 files changed

+89
-91
lines changed

cmd/compose/build.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
)
3535

3636
type buildOptions struct {
37-
*projectOptions
37+
*ProjectOptions
3838
composeOptions
3939
quiet bool
4040
pull bool
@@ -73,9 +73,9 @@ var printerModes = []string{
7373
buildx.PrinterModeQuiet,
7474
}
7575

76-
func buildCommand(p *projectOptions, backend api.Service) *cobra.Command {
76+
func buildCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
7777
opts := buildOptions{
78-
projectOptions: p,
78+
ProjectOptions: p,
7979
}
8080
cmd := &cobra.Command{
8181
Use: "build [OPTIONS] [SERVICE...]",
@@ -129,7 +129,7 @@ func buildCommand(p *projectOptions, backend api.Service) *cobra.Command {
129129
}
130130

131131
func runBuild(ctx context.Context, backend api.Service, opts buildOptions, services []string) error {
132-
project, err := opts.toProject(services, cli.WithResolvedPaths(true))
132+
project, err := opts.ToProject(services, cli.WithResolvedPaths(true))
133133
if err != nil {
134134
return err
135135
}

cmd/compose/completion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ func noCompletion() validArgsFn {
3232
}
3333
}
3434

35-
func completeServiceNames(p *projectOptions) validArgsFn {
35+
func completeServiceNames(p *ProjectOptions) validArgsFn {
3636
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
37-
project, err := p.toProject(nil)
37+
project, err := p.ToProject(nil)
3838
if err != nil {
3939
return nil, cobra.ShellCompDirectiveNoFileComp
4040
}

cmd/compose/compose.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func Adapt(fn Command) func(cmd *cobra.Command, args []string) error {
9191
})
9292
}
9393

94-
type projectOptions struct {
94+
type ProjectOptions struct {
9595
ProjectName string
9696
Profiles []string
9797
ConfigPaths []string
@@ -108,16 +108,16 @@ type ProjectFunc func(ctx context.Context, project *types.Project) error
108108
type ProjectServicesFunc func(ctx context.Context, project *types.Project, services []string) error
109109

110110
// WithProject creates a cobra run command from a ProjectFunc based on configured project options and selected services
111-
func (o *projectOptions) WithProject(fn ProjectFunc) func(cmd *cobra.Command, args []string) error {
111+
func (o *ProjectOptions) WithProject(fn ProjectFunc) func(cmd *cobra.Command, args []string) error {
112112
return o.WithServices(func(ctx context.Context, project *types.Project, services []string) error {
113113
return fn(ctx, project)
114114
})
115115
}
116116

117117
// WithServices creates a cobra run command from a ProjectFunc based on configured project options and selected services
118-
func (o *projectOptions) WithServices(fn ProjectServicesFunc) func(cmd *cobra.Command, args []string) error {
118+
func (o *ProjectOptions) WithServices(fn ProjectServicesFunc) func(cmd *cobra.Command, args []string) error {
119119
return Adapt(func(ctx context.Context, args []string) error {
120-
project, err := o.toProject(args, cli.WithResolvedPaths(true))
120+
project, err := o.ToProject(args, cli.WithResolvedPaths(true))
121121
if err != nil {
122122
return err
123123
}
@@ -126,7 +126,7 @@ func (o *projectOptions) WithServices(fn ProjectServicesFunc) func(cmd *cobra.Co
126126
})
127127
}
128128

129-
func (o *projectOptions) addProjectFlags(f *pflag.FlagSet) {
129+
func (o *ProjectOptions) addProjectFlags(f *pflag.FlagSet) {
130130
f.StringArrayVar(&o.Profiles, "profile", []string{}, "Specify a profile to enable")
131131
f.StringVarP(&o.ProjectName, "project-name", "p", "", "Project name")
132132
f.StringArrayVarP(&o.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
@@ -137,11 +137,11 @@ func (o *projectOptions) addProjectFlags(f *pflag.FlagSet) {
137137
_ = f.MarkHidden("workdir")
138138
}
139139

140-
func (o *projectOptions) projectOrName(services ...string) (*types.Project, string, error) {
140+
func (o *ProjectOptions) projectOrName(services ...string) (*types.Project, string, error) {
141141
name := o.ProjectName
142142
var project *types.Project
143143
if len(o.ConfigPaths) > 0 || o.ProjectName == "" {
144-
p, err := o.toProject(services)
144+
p, err := o.ToProject(services)
145145
if err != nil {
146146
envProjectName := os.Getenv("COMPOSE_PROJECT_NAME")
147147
if envProjectName != "" {
@@ -155,7 +155,7 @@ func (o *projectOptions) projectOrName(services ...string) (*types.Project, stri
155155
return project, name, nil
156156
}
157157

158-
func (o *projectOptions) toProjectName() (string, error) {
158+
func (o *ProjectOptions) toProjectName() (string, error) {
159159
if o.ProjectName != "" {
160160
return o.ProjectName, nil
161161
}
@@ -165,14 +165,14 @@ func (o *projectOptions) toProjectName() (string, error) {
165165
return envProjectName, nil
166166
}
167167

168-
project, err := o.toProject(nil)
168+
project, err := o.ToProject(nil)
169169
if err != nil {
170170
return "", err
171171
}
172172
return project.Name, nil
173173
}
174174

175-
func (o *projectOptions) toProject(services []string, po ...cli.ProjectOptionsFn) (*types.Project, error) {
175+
func (o *ProjectOptions) ToProject(services []string, po ...cli.ProjectOptionsFn) (*types.Project, error) {
176176
options, err := o.toProjectOptions(po...)
177177
if err != nil {
178178
return nil, compose.WrapComposeError(err)
@@ -222,7 +222,7 @@ func (o *projectOptions) toProject(services []string, po ...cli.ProjectOptionsFn
222222
return project, err
223223
}
224224

225-
func (o *projectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.ProjectOptions, error) {
225+
func (o *ProjectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.ProjectOptions, error) {
226226
return cli.NewProjectOptions(o.ConfigPaths,
227227
append(po,
228228
cli.WithWorkingDirectory(o.ProjectDir),
@@ -254,7 +254,7 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { //
254254
"commandConn.CloseRead:",
255255
))
256256

257-
opts := projectOptions{}
257+
opts := ProjectOptions{}
258258
var (
259259
ansi string
260260
noAnsi bool
@@ -383,7 +383,7 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { //
383383
return c
384384
}
385385

386-
func setEnvWithDotEnv(prjOpts *projectOptions) error {
386+
func setEnvWithDotEnv(prjOpts *ProjectOptions) error {
387387
options, err := prjOpts.toProjectOptions()
388388
if err != nil {
389389
return compose.WrapComposeError(err)

cmd/compose/convert.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
)
3636

3737
type convertOptions struct {
38-
*projectOptions
38+
*ProjectOptions
3939
Format string
4040
Output string
4141
quiet bool
@@ -50,9 +50,9 @@ type convertOptions struct {
5050
noConsistency bool
5151
}
5252

53-
func convertCommand(p *projectOptions, backend api.Service) *cobra.Command {
53+
func convertCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
5454
opts := convertOptions{
55-
projectOptions: p,
55+
ProjectOptions: p,
5656
}
5757
cmd := &cobra.Command{
5858
Aliases: []string{"config"},
@@ -112,13 +112,12 @@ func convertCommand(p *projectOptions, backend api.Service) *cobra.Command {
112112

113113
func runConvert(ctx context.Context, backend api.Service, opts convertOptions, services []string) error {
114114
var content []byte
115-
project, err := opts.toProject(services,
115+
project, err := opts.ToProject(services,
116116
cli.WithInterpolation(!opts.noInterpolate),
117117
cli.WithResolvedPaths(true),
118118
cli.WithNormalization(!opts.noNormalize),
119119
cli.WithConsistency(!opts.noConsistency),
120120
cli.WithDiscardEnvFile)
121-
122121
if err != nil {
123122
return err
124123
}
@@ -153,7 +152,7 @@ func runConvert(ctx context.Context, backend api.Service, opts convertOptions, s
153152
}
154153

155154
func runServices(opts convertOptions) error {
156-
project, err := opts.toProject(nil)
155+
project, err := opts.ToProject(nil)
157156
if err != nil {
158157
return err
159158
}
@@ -164,7 +163,7 @@ func runServices(opts convertOptions) error {
164163
}
165164

166165
func runVolumes(opts convertOptions) error {
167-
project, err := opts.toProject(nil)
166+
project, err := opts.ToProject(nil)
168167
if err != nil {
169168
return err
170169
}
@@ -179,7 +178,7 @@ func runHash(opts convertOptions) error {
179178
if opts.hash != "*" {
180179
services = append(services, strings.Split(opts.hash, ",")...)
181180
}
182-
project, err := opts.toProject(services)
181+
project, err := opts.ToProject(services)
183182
if err != nil {
184183
return err
185184
}
@@ -195,7 +194,7 @@ func runHash(opts convertOptions) error {
195194

196195
func runProfiles(opts convertOptions, services []string) error {
197196
set := map[string]struct{}{}
198-
project, err := opts.toProject(services)
197+
project, err := opts.ToProject(services)
199198
if err != nil {
200199
return err
201200
}
@@ -216,7 +215,7 @@ func runProfiles(opts convertOptions, services []string) error {
216215
}
217216

218217
func runConfigImages(opts convertOptions, services []string) error {
219-
project, err := opts.toProject(services)
218+
project, err := opts.ToProject(services)
220219
if err != nil {
221220
return err
222221
}

cmd/compose/cp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
type copyOptions struct {
30-
*projectOptions
30+
*ProjectOptions
3131

3232
source string
3333
destination string
@@ -37,9 +37,9 @@ type copyOptions struct {
3737
copyUIDGID bool
3838
}
3939

40-
func copyCommand(p *projectOptions, backend api.Service) *cobra.Command {
40+
func copyCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
4141
opts := copyOptions{
42-
projectOptions: p,
42+
ProjectOptions: p,
4343
}
4444
copyCmd := &cobra.Command{
4545
Use: `cp [OPTIONS] SERVICE:SRC_PATH DEST_PATH|-

cmd/compose/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type createOptions struct {
4343
quietPull bool
4444
}
4545

46-
func createCommand(p *projectOptions, backend api.Service) *cobra.Command {
46+
func createCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
4747
opts := createOptions{}
4848
cmd := &cobra.Command{
4949
Use: "create [OPTIONS] [SERVICE...]",

cmd/compose/down.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ import (
3131
)
3232

3333
type downOptions struct {
34-
*projectOptions
34+
*ProjectOptions
3535
removeOrphans bool
3636
timeChanged bool
3737
timeout int
3838
volumes bool
3939
images string
4040
}
4141

42-
func downCommand(p *projectOptions, backend api.Service) *cobra.Command {
42+
func downCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
4343
opts := downOptions{
44-
projectOptions: p,
44+
ProjectOptions: p,
4545
}
4646
downCmd := &cobra.Command{
4747
Use: "down [OPTIONS]",

cmd/compose/events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ type eventsOpts struct {
3131
json bool
3232
}
3333

34-
func eventsCommand(p *projectOptions, backend api.Service) *cobra.Command {
34+
func eventsCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
3535
opts := eventsOpts{
3636
composeOptions: &composeOptions{
37-
projectOptions: p,
37+
ProjectOptions: p,
3838
},
3939
}
4040
cmd := &cobra.Command{

cmd/compose/exec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ type execOpts struct {
4343
interactive bool
4444
}
4545

46-
func execCommand(p *projectOptions, dockerCli command.Cli, backend api.Service) *cobra.Command {
46+
func execCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *cobra.Command {
4747
opts := execOpts{
4848
composeOptions: &composeOptions{
49-
projectOptions: p,
49+
ProjectOptions: p,
5050
},
5151
}
5252
runCmd := &cobra.Command{

cmd/compose/images.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ import (
3434
)
3535

3636
type imageOptions struct {
37-
*projectOptions
37+
*ProjectOptions
3838
Quiet bool
3939
Format string
4040
}
4141

42-
func imagesCommand(p *projectOptions, backend api.Service) *cobra.Command {
42+
func imagesCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
4343
opts := imageOptions{
44-
projectOptions: p,
44+
ProjectOptions: p,
4545
}
4646
imgCmd := &cobra.Command{
4747
Use: "images [OPTIONS] [SERVICE...]",

0 commit comments

Comments
 (0)