From 120eea449ef5dcb793e9705424b75734108b67ff Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Tue, 12 Jan 2021 03:20:27 +0100 Subject: [PATCH] Remove the deprecated reset command The Go implementation had deprecated the reset command, right from the beginning, in favour of 'podman system reset'. It's time to finally remove it. https://github.com/containers/toolbox/pull/668 --- completion/bash/toolbox | 2 +- doc/meson.build | 1 - doc/toolbox-reset.1.md | 26 ----------- doc/toolbox.1.md | 4 -- src/cmd/reset.go | 96 ----------------------------------------- src/cmd/root.go | 6 +-- src/meson.build | 1 - 7 files changed, 3 insertions(+), 133 deletions(-) delete mode 100644 doc/toolbox-reset.1.md delete mode 100644 src/cmd/reset.go diff --git a/completion/bash/toolbox b/completion/bash/toolbox index 9ea387326..89ea20a85 100644 --- a/completion/bash/toolbox +++ b/completion/bash/toolbox @@ -18,7 +18,7 @@ __toolbox() { local MIN_VERSION=32 local RAWHIDE_VERSION=34 - local commands="create enter help init-container list reset rm rmi run" + local commands="create enter help init-container list rm rmi run" declare -A options local options=([create]="--container --distro --image --release" \ diff --git a/doc/meson.build b/doc/meson.build index bad1ceec3..172aee2df 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -11,7 +11,6 @@ manuals = [ 'toolbox-init-container.1', 'toolbox-help.1', 'toolbox-list.1', - 'toolbox-reset.1', 'toolbox-rm.1', 'toolbox-rmi.1', 'toolbox-run.1', diff --git a/doc/toolbox-reset.1.md b/doc/toolbox-reset.1.md deleted file mode 100644 index d90a0bfaa..000000000 --- a/doc/toolbox-reset.1.md +++ /dev/null @@ -1,26 +0,0 @@ -% toolbox-reset(1) - -## NAME -toolbox\-reset - Remove all local podman (and toolbox) state - -## SYNOPSIS -**toolbox reset** - -## DESCRIPTION - -Removes all existing podman (and toolbox) containers, images and configuration. -This can be used to factory reset your local Podman and Toolbox installations -when something has gone irrecoverably wrong with the `podman(1)` and -`toolbox(1)` commands. - -This command can only be used on the host, and not from within a toolbox -container, and is only expected to be used right after a fresh boot before any -other `podman(1)` or `toolbox(1)` commands have been invoked. - -## EXAMPLES - -### Reset a broken Podman and Toolbox installation - -``` -$ toolbox reset -``` diff --git a/doc/toolbox.1.md b/doc/toolbox.1.md index f534f66f8..2b1cc8da9 100644 --- a/doc/toolbox.1.md +++ b/doc/toolbox.1.md @@ -69,10 +69,6 @@ Initialize a running container. List existing toolbox containers and images. -**toolbox-reset(1)** - -Remove all local podman (and toolbox) state. - **toolbox-rm(1)** Remove one or more toolbox containers. diff --git a/src/cmd/reset.go b/src/cmd/reset.go deleted file mode 100644 index dd9a02fb8..000000000 --- a/src/cmd/reset.go +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright © 2019 – 2020 Red Hat Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cmd - -import ( - "errors" - "fmt" - "os" - "os/exec" - "strings" - "syscall" - - "github.com/containers/toolbox/pkg/utils" - "github.com/spf13/cobra" -) - -var resetCmd = &cobra.Command{ - Use: "reset", - Short: "Remove all local podman (and toolbox) state", - RunE: reset, -} - -func init() { - resetCmd.SetHelpFunc(resetHelp) - rootCmd.AddCommand(resetCmd) -} - -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 -} - -func resetHelp(cmd *cobra.Command, args []string) { - if utils.IsInsideContainer() { - if !utils.IsInsideToolboxContainer() { - fmt.Fprintf(os.Stderr, "Error: this is not a toolbox container\n") - return - } - - if _, err := utils.ForwardToHost(); err != nil { - fmt.Fprintf(os.Stderr, "Error: %s\n", err) - return - } - - return - } - - if err := utils.ShowManual("toolbox-reset"); err != nil { - fmt.Fprintf(os.Stderr, "Error: %s\n", err) - return - } -} diff --git a/src/cmd/root.go b/src/cmd/root.go index 9651b778b..5c2234a0d 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -141,10 +141,8 @@ func preRun(cmd *cobra.Command, args []string) error { toolboxPath = os.Getenv("TOOLBOX_PATH") logrus.Debugf("TOOLBOX_PATH is %s", toolboxPath) - if cmd.Use != "reset" { - if err := migrate(); err != nil { - return err - } + if err := migrate(); err != nil { + return err } return nil diff --git a/src/meson.build b/src/meson.build index fd5ec37d3..04423d997 100644 --- a/src/meson.build +++ b/src/meson.build @@ -10,7 +10,6 @@ sources = files( 'cmd/help.go', 'cmd/initContainer.go', 'cmd/list.go', - 'cmd/reset.go', 'cmd/rm.go', 'cmd/rmi.go', 'cmd/root.go',