func doRemove(ctx *cli.Context, config *config.Config, dockerCli *docker.Client, auth *compose.AuthConfig) error { compose, err := compose.New(&compose.Config{ Manifest: config, Docker: dockerCli, DryRun: ctx.Bool("dry"), Remove: true, Auth: auth, }) if err != nil { return err } return compose.RunAction() }
func runCommand(ctx *cli.Context) { ansibleResp := initAnsubleResp(ctx) // TODO: here we duplicate fatalf in both run(), pull() and clean() // maybe refactor to make it cleaner fatalf := func(err error) { if ansibleResp != nil { ansibleResp.Error(err).WriteTo(os.Stdout) } log.Fatal(err) } initLogs(ctx) dockerCli := initDockerClient(ctx) config := initComposeConfig(ctx, dockerCli) auth := initAuthConfig(ctx) compose, err := compose.New(&compose.Config{ Manifest: config, Docker: dockerCli, Force: ctx.Bool("force"), DryRun: ctx.Bool("dry"), Attach: ctx.Bool("attach"), Wait: ctx.Duration("wait"), Pull: ctx.Bool("pull"), Auth: auth, }) if err != nil { fatalf(err) } // in case of --force given, first remove all existing containers if ctx.Bool("force") { if err := doRemove(ctx, config, dockerCli, auth); err != nil { fatalf(err) } } if err := compose.RunAction(); err != nil { fatalf(err) } if ansibleResp != nil { // ansibleResp.Success("done hehe").WriteTo(os.Stdout) compose.WritePlan(ansibleResp).WriteTo(os.Stdout) } }