Skip to content

Commit

Permalink
Add "--remove-containers" flag to "stop" command
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlemke committed May 14, 2020
1 parent aaa2eda commit 6279242
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
5 changes: 3 additions & 2 deletions cmd/beach/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package cmd

import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/flownative/localbeach/pkg/beachsandbox"
"github.com/flownative/localbeach/pkg/exec"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var pull bool
Expand Down Expand Up @@ -48,6 +48,7 @@ func handleStartRun(cmd *cobra.Command, args []string) {
}

if pull {
log.Debug("Pulling images ...")
commandArgs = []string{"-f", ".localbeach.docker-compose.yaml", "pull"}
_, err := exec.RunCommand("docker-compose", commandArgs)
if err != nil {
Expand Down
49 changes: 33 additions & 16 deletions cmd/beach/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,49 @@
package cmd

import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/flownative/localbeach/pkg/beachsandbox"
"github.com/flownative/localbeach/pkg/exec"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var removeContainers bool

// stopCmd represents the stop command
var stopCmd = &cobra.Command{
Use: "stop",
Short: "Stop the Local Beach instance in the current directory",
Long: "",
Run: func(cmd *cobra.Command, args []string) {
_, err := beachsandbox.GetActiveSandbox()
if err != nil {
log.Fatal(err)
return
}

commandArgs := []string{"-f", ".localbeach.docker-compose.yaml", "stop"}
err = exec.RunInteractiveCommand("docker-compose", commandArgs)
if err != nil {
log.Fatal(err)
return
}
Args: cobra.ExactArgs(0),
Run: handleStopRun,
}

func init() {
rootCmd.AddCommand(stopCmd)
stopCmd.Flags().BoolVarP(&removeContainers, "remove-containers", "r", false, "Remove containers after they stopped")
}

func handleStopRun(cmd *cobra.Command, args []string) {
_, err := beachsandbox.GetActiveSandbox()
if err != nil {
log.Fatal(err)
return
}

commandArgs := []string{"-f", ".localbeach.docker-compose.yaml"}

if removeContainers {
commandArgs = append(commandArgs, "down")
} else {
commandArgs = append(commandArgs, "stop")
}

err = exec.RunInteractiveCommand("docker-compose", commandArgs)
if err != nil {
log.Fatal(err)
return
},
}
return
}

func init() {
Expand Down

0 comments on commit 6279242

Please sign in to comment.