Skip to content

Commit

Permalink
Add --prune for up command
Browse files Browse the repository at this point in the history
Signed-off-by: Remco Kranenburg <remco.kranenburg@crunchr.com>
  • Loading branch information
Remco Kranenburg committed Dec 19, 2024
1 parent 56e92e3 commit 4b34268
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type upOptions struct {
wait bool
waitTimeout int
watch bool
prune bool
navigationMenu bool
navigationMenuChanged bool
}
Expand Down Expand Up @@ -170,6 +171,7 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *c
flags.BoolVar(&up.wait, "wait", false, "Wait for services to be running|healthy. Implies detached mode.")
flags.IntVar(&up.waitTimeout, "wait-timeout", 0, "Maximum duration in seconds to wait for the project to be running|healthy")
flags.BoolVarP(&up.watch, "watch", "w", false, "Watch source code and rebuild/refresh containers when files are updated.")
flags.BoolVar(&up.prune, "prune", false, "Prune dangling images on rebuild")
flags.BoolVar(&up.navigationMenu, "menu", false, "Enable interactive shortcuts when running attached. Incompatible with --detach. Can also be enable/disable by setting COMPOSE_MENU environment var.")

return upCmd
Expand Down Expand Up @@ -207,6 +209,9 @@ func validateFlags(up *upOptions, create *createOptions) error {
if create.noBuild && up.watch {
return fmt.Errorf("--no-build and --watch are incompatible")
}
if !up.watch && up.prune {
return fmt.Errorf("--prune can only be used with --watch")
}
return nil
}

Expand Down Expand Up @@ -310,6 +315,7 @@ func runUp(
Wait: upOptions.wait,
WaitTimeout: timeout,
Watch: upOptions.watch,
Prune: upOptions.prune,
Services: services,
NavigationMenu: upOptions.navigationMenu && ui.Mode != "plain",
},
Expand Down
1 change: 1 addition & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ type StartOptions struct {
// Services passed in the command line to be started
Services []string
Watch bool
Prune bool
NavigationMenu bool
}

Expand Down
1 change: 1 addition & 0 deletions pkg/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
return s.watch(ctx, doneCh, project, options.Start.Services, api.WatchOptions{
Build: &buildOpts,
LogTo: options.Start.Attach,
Prune: options.Start.Prune,
})
})
}
Expand Down

0 comments on commit 4b34268

Please sign in to comment.