mirror of
https://github.com/docker/compose.git
synced 2026-08-04 14:47:40 +00:00
Add rm command
Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
parent
1a3365fa37
commit
40fa78ac5d
7 changed files with 96 additions and 7 deletions
51
cli/cmd/rm.go
Normal file
51
cli/cmd/rm.go
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/api/client"
|
||||
)
|
||||
|
||||
type rmOpts struct {
|
||||
force bool
|
||||
}
|
||||
|
||||
// RmCommand deletes containers
|
||||
func RmCommand() *cobra.Command {
|
||||
var opts rmOpts
|
||||
cmd := &cobra.Command{
|
||||
Use: "rm",
|
||||
Aliases: []string{"delete"},
|
||||
Short: "Remove containers",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
var errs []string
|
||||
c, err := client.New(cmd.Context())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cannot connect to backend")
|
||||
}
|
||||
|
||||
for _, id := range args {
|
||||
err := c.ContainerService().Delete(cmd.Context(), id, opts.force)
|
||||
if err != nil {
|
||||
errs = append(errs, err.Error())
|
||||
continue
|
||||
}
|
||||
println(id)
|
||||
}
|
||||
|
||||
if len(errs) > 0 {
|
||||
return errors.New(strings.Join(errs, "\n"))
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().BoolVarP(&opts.force, "force", "f", false, "Force removal")
|
||||
|
||||
return cmd
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue