Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 66231c5

Browse files
committed
Refactor CLI Populate function
Signed-off-by: Josh Curl <[email protected]>
1 parent 0843a75 commit 66231c5

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

cli/command/command.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
package command
22

33
import (
4+
"os"
5+
46
"github.com/docker/libcompose/cli/app"
7+
"github.com/docker/libcompose/project"
58
"github.com/urfave/cli"
69
)
710

11+
// Populate updates the specified project context based on command line arguments and subcommands.
12+
func Populate(context *project.Context, c *cli.Context) {
13+
context.ComposeFiles = c.GlobalStringSlice("file")
14+
15+
if len(context.ComposeFiles) == 0 {
16+
context.ComposeFiles = []string{"docker-compose.yml"}
17+
if _, err := os.Stat("docker-compose.override.yml"); err == nil {
18+
context.ComposeFiles = append(context.ComposeFiles, "docker-compose.override.yml")
19+
}
20+
}
21+
22+
context.ProjectName = c.GlobalString("project-name")
23+
}
24+
825
// CreateCommand defines the libcompose create subcommand.
926
func CreateCommand(factory app.ProjectFactory) cli.Command {
1027
return cli.Command{

cli/docker/app/commands.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package app
22

33
import (
44
"github.com/Sirupsen/logrus"
5+
"github.com/docker/libcompose/cli/command"
56
"github.com/docker/libcompose/docker"
67
"github.com/docker/libcompose/docker/client"
78
"github.com/urfave/cli"
@@ -41,6 +42,8 @@ func DockerClientFlags() []cli.Flag {
4142

4243
// Populate updates the specified docker context based on command line arguments and subcommands.
4344
func Populate(context *docker.Context, c *cli.Context) {
45+
command.Populate(&context.Context, c)
46+
4447
context.ConfigDir = c.String("configdir")
4548

4649
opts := client.Options{}

cli/docker/app/factory.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package app
22

33
import (
4-
"os"
5-
64
"github.com/docker/libcompose/cli/logger"
75
"github.com/docker/libcompose/docker"
86
"github.com/docker/libcompose/project"
@@ -18,17 +16,5 @@ func (p *ProjectFactory) Create(c *cli.Context) (project.APIProject, error) {
1816
context := &docker.Context{}
1917
context.LoggerFactory = logger.NewColorLoggerFactory()
2018
Populate(context, c)
21-
22-
context.ComposeFiles = c.GlobalStringSlice("file")
23-
24-
if len(context.ComposeFiles) == 0 {
25-
context.ComposeFiles = []string{"docker-compose.yml"}
26-
if _, err := os.Stat("docker-compose.override.yml"); err == nil {
27-
context.ComposeFiles = append(context.ComposeFiles, "docker-compose.override.yml")
28-
}
29-
}
30-
31-
context.ProjectName = c.GlobalString("project-name")
32-
3319
return docker.NewProject(context, nil)
3420
}

0 commit comments

Comments
 (0)