Skip to content

Commit 6c6c5ec

Browse files
authored
Support for optional service names on down (#660)
1 parent 78a7bbe commit 6c6c5ec

File tree

7 files changed

+20
-9
lines changed

7 files changed

+20
-9
lines changed

src/cmd/cli/command/compose.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,15 @@ func makeComposeStopCmd() *cobra.Command {
249249

250250
func makeComposeDownCmd() *cobra.Command {
251251
composeDownCmd := &cobra.Command{
252-
Use: "down",
253-
Aliases: []string{"rm"},
252+
Use: "down [SERVICE...]",
253+
Aliases: []string{"rm", "remove"}, // like docker stack
254254
Annotations: authNeededAnnotation,
255-
Args: cobra.NoArgs, // TODO: takes optional list of service names
256255
Short: "Reads a Compose file and deprovisions its services",
257256
RunE: func(cmd *cobra.Command, args []string) error {
258257
var detach, _ = cmd.Flags().GetBool("detach")
259258

260259
since := time.Now()
261-
etag, err := cli.ComposeDown(cmd.Context(), client)
260+
etag, err := cli.ComposeDown(cmd.Context(), client, args...)
262261
if err != nil {
263262
if connect.CodeOf(err) == connect.CodeNotFound {
264263
// Show a warning (not an error) if the service was not found

src/pkg/cli/client/client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ type Client interface {
4242
BootstrapCommand(context.Context, string) (types.ETag, error)
4343
BootstrapList(context.Context) ([]string, error)
4444
CreateUploadURL(context.Context, *defangv1.UploadURLRequest) (*defangv1.UploadURLResponse, error)
45-
// Deprecated: Use Deploy or Destroy instead.
4645
Delete(context.Context, *defangv1.DeleteRequest) (*defangv1.DeleteResponse, error)
4746
DeleteConfig(context.Context, *defangv1.Secrets) error
4847
Deploy(context.Context, *defangv1.DeployRequest) (*defangv1.DeployResponse, error)

src/pkg/cli/composeDown.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,29 @@ import (
66
"github.com/DefangLabs/defang/src/pkg/cli/client"
77
"github.com/DefangLabs/defang/src/pkg/term"
88
"github.com/DefangLabs/defang/src/pkg/types"
9+
defangv1 "github.com/DefangLabs/defang/src/protos/io/defang/v1"
910
)
1011

11-
func ComposeDown(ctx context.Context, client client.Client) (types.ETag, error) {
12+
func ComposeDown(ctx context.Context, client client.Client, names ...string) (types.ETag, error) {
1213
projectName, err := client.LoadProjectName(ctx)
1314
if err != nil {
1415
return "", err
1516
}
16-
term.Debugf("Destroying project %q", projectName)
17+
18+
term.Debugf("Destroying project %q %q", projectName, names)
1719

1820
if DoDryRun {
1921
return "", ErrDryRun
2022
}
2123

22-
return client.Destroy(ctx)
24+
if len(names) == 0 {
25+
// If no names are provided, destroy the entire project
26+
return client.Destroy(ctx)
27+
}
28+
29+
resp, err := client.Delete(ctx, &defangv1.DeleteRequest{Names: names})
30+
if err != nil {
31+
return "", err
32+
}
33+
return resp.Etag, nil
2334
}

src/pkg/cli/composeRestart.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/DefangLabs/defang/src/pkg/types"
99
)
1010

11+
// Deprecated: this doesn't do the right thing right now
1112
func ComposeRestart(ctx context.Context, client client.Client) (types.ETag, error) {
1213
project, err := client.LoadProject(ctx)
1314
if err != nil {

src/pkg/cli/composeStop.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/DefangLabs/defang/src/pkg/types"
99
)
1010

11+
// Deprecated: this doesn't do the right thing right now
1112
func ComposeStop(ctx context.Context, client client.Client) (types.ETag, error) {
1213
project, err := client.LoadProject(ctx)
1314
if err != nil {

src/pkg/cli/delete.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
defangv1 "github.com/DefangLabs/defang/src/protos/io/defang/v1"
1010
)
1111

12-
// Deprecated: Use ComposeStop instead.
1312
func Delete(ctx context.Context, client client.Client, names ...string) (types.ETag, error) {
1413
term.Debug("Deleting service", names)
1514

src/pkg/cli/restart.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/DefangLabs/defang/src/pkg/types"
99
)
1010

11+
// Deprecated: this doesn't do the right thing right now
1112
func Restart(ctx context.Context, client client.Client, names ...string) (types.ETag, error) {
1213
term.Debug("Restarting service", names)
1314

0 commit comments

Comments
 (0)