Skip to content
Closed
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions cmd/buildah/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
)

var (
deleteDescription = "Deletes working container(s), unmounting them if necessary"
deleteDescription = "Deletes images and working container(s), unmounting them if necessary"
deleteCommand = cli.Command{
Name: "delete",
Usage: "Deletes working container(s)",
Usage: "Deletes images and working container(s)",
Description: deleteDescription,
Action: deleteCmd,
ArgsUsage: "CONTAINER-NAME-OR-ID [...]",
Expand All @@ -30,12 +30,16 @@ func deleteCmd(c *cli.Context) error {
for _, name := range args {
builder, err := openBuilder(store, name)
if err != nil {
return fmt.Errorf("error reading build container %q: %v", name, err)
/* Maybe this was an image attempt to delete it */
_, err = store.DeleteImage(name, true)
return fmt.Errorf("error deleting image or container %q: %v", name, err)
}

err = builder.Delete()
if err != nil {
return fmt.Errorf("error deleting container %q: %v", builder.Container, err)
if err != nil {
return fmt.Errorf("error deleting container %q: %v", name, err)
}
}
}

Expand Down
89 changes: 79 additions & 10 deletions cmd/buildah/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ var (
Name: "quiet",
Usage: "omit column headings",
},
cli.BoolFlag{
Name: "containers",
Usage: "print containers only",
},
cli.BoolFlag{
Name: "images",
Usage: "print images only",
},
cli.BoolFlag{
Name: "no-trunc",
Usage: "don't truncate output",
},
}
listDescription = "Lists containers which appear to be " + buildah.Package + " working containers, their\n names and IDs, and the names and IDs of the images from which they were\n initialized"

Expand All @@ -38,19 +50,76 @@ func listCmd(c *cli.Context) error {
quiet = c.Bool("quiet")
}

builders, err := openBuilders(store)
if err != nil {
return fmt.Errorf("error reading build containers: %v", err)
truncate := true
if c.IsSet("no-trunc") {
truncate = !c.Bool("no-trunc")
}
if len(builders) > 0 && !quiet {
fmt.Printf("%-64s %-64s %-10s %s\n", "CONTAINER ID", "IMAGE ID", "IMAGE NAME", "CONTAINER NAME")

containers := true
if c.IsSet("images") {
containers = !c.Bool("images")
}
for _, builder := range builders {
if builder.FromImage == "" {
builder.FromImage = buildah.BaseImageFakeName
}
fmt.Printf("%-64s %-64s %-10s %s\n", builder.ContainerID, builder.FromImageID, builder.FromImage, builder.Container)

images := true
if c.IsSet("containers") {
images = !c.Bool("containers")
}

if images {
images, err := store.Images()
if err != nil {
return err
}

if len(images) > 0 && !quiet {
fmt.Printf("\nIMAGES\n\n")
if truncate {
fmt.Printf("%-12s %-64s\n", "IMAGE ID", "IMAGE NAME")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to do the full 64 for the name or a shorter version here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are trying to stay within 80 chars, I thought we would just do 64, also the Name is somewhat important while the ID is pretty much only used by the computer.
We have a bug in this patch in that you can not use the short name for delete operations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's works for me, especially given the bug, I asked because I thought you shortened it at line 93. However i need to read more carefully, you didn't shorten it there either.

} else {
fmt.Printf("%-64s %-64s\n", "IMAGE ID", "IMAGE NAME")
}
}
for _, image := range images {
if quiet {
fmt.Printf("%s\n", image.ID)
continue
}
names := []string{""}
if len(image.Names) > 0 {
names = image.Names
}
for _, name := range names {
if truncate {
fmt.Printf("%-12.12s %s\n", image.ID, name)
} else {
fmt.Printf("%-64s %s\n", image.ID, name)
}
}
}
}
if containers {
builders, err := openBuilders(store)
if err != nil {
return fmt.Errorf("error reading build containers: %v", err)
}
if len(builders) > 0 && !quiet {
fmt.Printf("\nCONTAINERS\n\n")
if truncate {
fmt.Printf("%.12s %.12s %-10s %s\n", "CONTAINER ID", "IMAGE ID", "IMAGE NAME", "CONTAINER NAME")
} else {
fmt.Printf("%.64s %.64s %-10s %s\n", "CONTAINER ID", "IMAGE ID", "IMAGE NAME", "CONTAINER NAME")
}
}
for _, builder := range builders {
if builder.FromImage == "" {
builder.FromImage = buildah.BaseImageFakeName
}
if truncate {
fmt.Printf("%-12.12s %-12.12s %-10s %s\n", builder.ContainerID, builder.FromImageID, builder.FromImage, builder.Container)
} else {
fmt.Printf("%.64s %.64s %-10s %s\n", builder.ContainerID, builder.FromImageID, builder.FromImage, builder.Container)
}
}
}
return nil
}