diff --git a/src/cmd/reset.go b/src/cmd/reset.go index 9e2fa0f..dd9a02f 100644 --- a/src/cmd/reset.go +++ b/src/cmd/reset.go @@ -17,8 +17,12 @@ package cmd import ( + "errors" "fmt" "os" + "os/exec" + "strings" + "syscall" "github.com/containers/toolbox/pkg/utils" "github.com/spf13/cobra" @@ -36,6 +40,37 @@ func init() { } func reset(cmd *cobra.Command, args []string) error { + fmt.Fprintf(os.Stderr, "'%s reset' is deprecated in favor of 'podman system reset'.\n", executableBase) + + if utils.IsInsideContainer() { + var builder strings.Builder + fmt.Fprintf(&builder, "the 'reset' command cannot be used inside containers\n") + fmt.Fprintf(&builder, "Run '%s --help' for usage.", executableBase) + + errMsg := builder.String() + return errors.New(errMsg) + } + + podmanBinary, err := exec.LookPath("podman") + if err != nil { + if errors.Is(err, exec.ErrNotFound) { + return errors.New("podman(1) not found") + } + + return errors.New("failed to lookup podman(1)") + } + + podmanArgs := []string{"podman", "system", "reset"} + if rootFlags.assumeYes { + podmanArgs = append(podmanArgs, []string{"--force"}...) + } + + env := os.Environ() + + if err := syscall.Exec(podmanBinary, podmanArgs, env); err != nil { + return errors.New("failed to invoke podman(1)") + } + return nil }