mirror of https://github.com/docker/compose.git
Commands run and rm only call a func
This commit is contained in:
parent
42c72c365c
commit
962efef48c
|
@ -1,6 +1,7 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
@ -23,14 +24,24 @@ func RmCommand() *cobra.Command {
|
|||
Short: "Remove containers",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := client.New(cmd.Context())
|
||||
return runRm(cmd.Context(), args, opts)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().BoolVarP(&opts.force, "force", "f", false, "Force removal")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runRm(ctx context.Context, args []string, opts rmOpts) error {
|
||||
c, err := client.New(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cannot connect to backend")
|
||||
}
|
||||
|
||||
var errs *multierror.Error
|
||||
for _, id := range args {
|
||||
err := c.ContainerService().Delete(cmd.Context(), id, opts.force)
|
||||
err := c.ContainerService().Delete(ctx, id, opts.force)
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
continue
|
||||
|
@ -39,10 +50,4 @@ func RmCommand() *cobra.Command {
|
|||
}
|
||||
|
||||
return errs.ErrorOrNil()
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().BoolVarP(&opts.force, "force", "f", false, "Force removal")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -46,11 +46,7 @@ func Command() *cobra.Command {
|
|||
Short: "Run a container",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := runRun(cmd.Context(), args[0], opts); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(opts.name)
|
||||
return nil
|
||||
return runRun(cmd.Context(), args[0], opts)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -71,7 +67,12 @@ func runRun(ctx context.Context, image string, opts runOpts) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return c.ContainerService().Run(ctx, project)
|
||||
if err = c.ContainerService().Run(ctx, project); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(opts.name)
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func getRandomName() string {
|
||||
|
|
Loading…
Reference in New Issue