(cmd *cobra.Command, args []string)
| 57 | } |
| 58 | |
| 59 | func rm(cmd *cobra.Command, args []string) error { |
| 60 | if utils.IsInsideContainer() { |
| 61 | if !utils.IsInsideToolboxContainer() { |
| 62 | return errors.New("this is not a Toolbx container") |
| 63 | } |
| 64 | |
| 65 | exitCode, err := utils.ForwardToHost() |
| 66 | return &exitError{exitCode, err} |
| 67 | } |
| 68 | |
| 69 | if rmFlags.deleteAll { |
| 70 | toolboxContainers, err := getContainers() |
| 71 | if err != nil { |
| 72 | return err |
| 73 | } |
| 74 | |
| 75 | for _, container := range toolboxContainers { |
| 76 | containerID := container.ID() |
| 77 | if err := podman.RemoveContainer(containerID, rmFlags.forceDelete); err != nil { |
| 78 | fmt.Fprintf(os.Stderr, "Error: %s\n", err) |
| 79 | continue |
| 80 | } |
| 81 | } |
| 82 | } else { |
| 83 | if len(args) == 0 { |
| 84 | var builder strings.Builder |
| 85 | fmt.Fprintf(&builder, "missing argument for \"rm\"\n") |
| 86 | fmt.Fprintf(&builder, "Run '%s --help' for usage.", executableBase) |
| 87 | |
| 88 | errMsg := builder.String() |
| 89 | return errors.New(errMsg) |
| 90 | } |
| 91 | |
| 92 | for _, container := range args { |
| 93 | containerObj, err := podman.InspectContainer(container) |
| 94 | if err != nil { |
| 95 | fmt.Fprintf(os.Stderr, "Error: failed to inspect container %s\n", container) |
| 96 | continue |
| 97 | } |
| 98 | |
| 99 | if !containerObj.IsToolbx() { |
| 100 | fmt.Fprintf(os.Stderr, "Error: %s is not a Toolbx container\n", container) |
| 101 | continue |
| 102 | } |
| 103 | |
| 104 | if err := podman.RemoveContainer(container, rmFlags.forceDelete); err != nil { |
| 105 | fmt.Fprintf(os.Stderr, "Error: %s\n", err) |
| 106 | continue |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return nil |
| 112 | } |
| 113 | |
| 114 | func rmHelp(cmd *cobra.Command, args []string) { |
| 115 | if utils.IsInsideContainer() { |
nothing calls this directly
no test coverage detected