Skip to content

Commit 94ce70a

Browse files
committed
feat: Remove command has "delete" alias. Remove command can accept multiple workload names.
1 parent 1145285 commit 94ce70a

1 file changed

Lines changed: 35 additions & 34 deletions

File tree

‎pkg/commands/remove.go‎

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func Remove() *cli.Command {
1818
return &cli.Command{
1919
Name: "remove",
20-
Aliases: []string{"rm"},
20+
Aliases: []string{"rm", "delete"},
2121
Usage: "Tear down a running bridge",
2222
Flags: []cli.Flag{
2323
&cli.StringFlag{
@@ -32,23 +32,14 @@ func Remove() *cli.Command {
3232
Usage: "Auto-accept all confirmation prompts",
3333
},
3434
},
35-
Arguments: []cli.Argument{
36-
&cli.StringArg{
37-
Name: "name",
38-
UsageText: "Name of the bridge to remove",
39-
Config: cli.StringConfig{
40-
TrimSpace: true,
41-
},
42-
},
43-
},
4435
Action: runRemove,
4536
}
4637
}
4738

4839
func runRemove(ctx context.Context, c *cli.Command) error {
49-
name := c.StringArg("name")
50-
if name == "" {
51-
return fmt.Errorf("bridge name is required")
40+
names := c.Args().Slice()
41+
if len(names) == 0 {
42+
return fmt.Errorf("at least one bridge name is required")
5243
}
5344
adminAddr := c.String("admin-addr")
5445

@@ -60,13 +51,7 @@ func runRemove(ctx context.Context, c *cli.Command) error {
6051
return fmt.Errorf("failed to get device identity: %w", err)
6152
}
6253

63-
// Normalize the name: if the user passes the short deployment name
64-
// (e.g. "api-feature-flags"), append the device suffix so it matches
65-
// the bridge resource name used by create/exec.
6654
suffix := "-" + identity.ShortDeviceID(deviceID)
67-
if !strings.HasSuffix(name, suffix) {
68-
name = identity.BridgeResourceName(deviceID, name)
69-
}
7055

7156
sp := interact.NewSpinner(w, "Connecting to bridge administrator...")
7257
ctx = interact.WithSpinner(ctx, sp)
@@ -79,23 +64,39 @@ func runRemove(ctx context.Context, c *cli.Command) error {
7964
}
8065
defer adm.Close()
8166

82-
sp.SetTitle("Removing bridge...")
67+
var errs []error
68+
ct := container.NewDockerClient()
69+
for _, name := range names {
70+
if !strings.HasSuffix(name, suffix) {
71+
name = identity.BridgeResourceName(deviceID, name)
72+
}
8373

84-
_, err = adm.DeleteBridge(ctx, &bridgev1.DeleteBridgeRequest{
85-
DeviceId: deviceID,
86-
Name: name,
87-
})
88-
sp.Stop()
89-
if err != nil {
90-
return fmt.Errorf("failed to remove bridge: %w", err)
91-
}
74+
sp.SetTitle(fmt.Sprintf("Removing bridge %q...", name))
9275

93-
// Clean up local containers for this bridge.
94-
container.NewDockerClient().StopAll(ctx, container.StopAllOpts{
95-
Labels: map[string]string{labelBridgeDeployment: name},
96-
})
76+
_, err = adm.DeleteBridge(ctx, &bridgev1.DeleteBridgeRequest{
77+
DeviceId: deviceID,
78+
Name: name,
79+
})
80+
if err != nil {
81+
errs = append(errs, fmt.Errorf("failed to remove bridge %q: %w", name, err))
82+
continue
83+
}
9784

98-
p.Newline()
99-
p.Success(fmt.Sprintf("Bridge %q removed", name))
85+
ct.StopAll(ctx, container.StopAllOpts{
86+
Labels: map[string]string{labelBridgeDeployment: name},
87+
})
88+
89+
p.Newline()
90+
p.Success(fmt.Sprintf("Bridge %q removed", name))
91+
}
92+
sp.Stop()
93+
94+
if len(errs) > 0 {
95+
msgs := make([]string, len(errs))
96+
for i, e := range errs {
97+
msgs[i] = e.Error()
98+
}
99+
return fmt.Errorf("%s", strings.Join(msgs, "\n"))
100+
}
100101
return nil
101102
}

0 commit comments

Comments
 (0)