Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

destroy cleanup #133

Merged
merged 2 commits into from
Nov 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/srl-wim/container-lab/clab"
)

var cleanup bool

// destroyCmd represents the destroy command
var destroyCmd = &cobra.Command{
Use: "destroy",
Expand All @@ -38,6 +40,12 @@ var destroyCmd = &cobra.Command{
return err
}

if cleanup {
err = os.RemoveAll(c.Dir.Lab)
if err != nil {
log.Errorf("error deleting lab directory: %v", err)
}
}
containers, err := c.ListContainers(ctx, []string{fmt.Sprintf("containerlab=lab-%s", c.Config.Name)})
if err != nil {
return fmt.Errorf("could not list containers: %v", err)
Expand Down Expand Up @@ -81,6 +89,7 @@ var destroyCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(destroyCmd)
destroyCmd.Flags().BoolVarP(&cleanup, "cleanup", "", false, "delete lab directory")
}

func deleteEntriesFromHostsFile(containers []types.Container, bridgeName string) error {
Expand Down