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

Commit c82f292

Browse files
authored
Merge pull request #273 from vdemeester/add-config-command
Add a config command
2 parents 5588741 + 4eb23be commit c82f292

File tree

12 files changed

+119
-3
lines changed

12 files changed

+119
-3
lines changed

cli/app/app.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ func ProjectKill(p project.APIProject, c *cli.Context) error {
275275
return nil
276276
}
277277

278+
// ProjectConfig validates and print the compose file.
279+
func ProjectConfig(p project.APIProject, c *cli.Context) error {
280+
yaml, err := p.Config()
281+
if err != nil {
282+
return cli.NewExitError(err.Error(), 1)
283+
}
284+
fmt.Println(yaml)
285+
return nil
286+
}
287+
278288
// ProjectPause pauses service containers.
279289
func ProjectPause(p project.APIProject, c *cli.Context) error {
280290
err := p.Pause(context.Background(), c.Args()...)

cli/command/command.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ func CreateCommand(factory app.ProjectFactory) cli.Command {
4545
}
4646
}
4747

48+
// ConfigCommand defines the libcompose config subcommand
49+
func ConfigCommand(factory app.ProjectFactory) cli.Command {
50+
return cli.Command{
51+
Name: "config",
52+
Usage: "Validate and view the compose file.",
53+
Action: app.WithProject(factory, app.ProjectConfig),
54+
}
55+
}
56+
4857
// BuildCommand defines the libcompose build subcommand.
4958
func BuildCommand(factory app.ProjectFactory) cli.Command {
5059
return cli.Command{

cli/main/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func main() {
2323
app.Flags = append(command.CommonFlags(), dockerApp.DockerClientFlags()...)
2424
app.Commands = []cli.Command{
2525
command.BuildCommand(factory),
26+
command.ConfigCommand(factory),
2627
command.CreateCommand(factory),
2728
command.EventsCommand(factory),
2829
command.DownCommand(factory),

config/merge_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,16 @@ services:
5858
child := config["child"]
5959

6060
if parent.Image != "foo" {
61-
t.Fatal("Invalid image", parent.Image)
61+
t.Fatal("Invalid parent image", parent.Image)
6262
}
6363

64+
t.Logf("%#v", config["child"])
6465
if child.Build.Context != "" {
65-
t.Fatal("Invalid build", child.Build)
66+
t.Fatalf("Invalid build %#v", child.Build)
6667
}
6768

6869
if child.Image != "foo" {
69-
t.Fatal("Invalid image", child.Image)
70+
t.Fatal("Invalid child image", child.Image)
7071
}
7172
}
7273
}

config/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ func (c *ServiceConfigs) Keys() []string {
226226
return keys
227227
}
228228

229+
// All returns all the config at once
230+
func (c *ServiceConfigs) All() map[string]*ServiceConfig {
231+
c.mu.RLock()
232+
defer c.mu.RUnlock()
233+
return c.m
234+
}
235+
229236
// RawService is represent a Service in map form unparsed
230237
type RawService map[string]interface{}
231238

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "2.0"
2+
services:
3+
db:
4+
image: busybox:latest
5+
command: top
6+
web:
7+
image: busybox:latest
8+
command: top
9+
depends_on:
10+
- db
11+
console:
12+
image: busybox:latest
13+
command: top

integration/assets/v2-full/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
FROM busybox:latest
3+
RUN echo something
4+
CMD top
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
version: "2"
3+
4+
volumes:
5+
data:
6+
driver: local
7+
8+
networks:
9+
front: {}
10+
11+
services:
12+
web:
13+
build:
14+
context: .
15+
networks:
16+
- front
17+
- default
18+
volumes_from:
19+
- other
20+
21+
other:
22+
image: busybox:latest
23+
command: top
24+
volumes:
25+
- /data
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: "2"
2+
services:
3+
simple:
4+
image: busybox:latest
5+
command: top
6+
another:
7+
image: busybox:latest
8+
command: top
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: "2"
2+
services:
3+
simple:
4+
image: busybox:latest
5+
command: top
6+
links:
7+
- another
8+
another:
9+
image: busybox:latest
10+
command: top

0 commit comments

Comments
 (0)