cmd/reset: Implement the reset command in Go
https://github.com/containers/toolbox/pull/318
This commit is contained in:
parent
662bd89931
commit
ebd92b9905
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue