Skip to content

Commit

Permalink
cmd/reset: Implement the reset command in Go
Browse files Browse the repository at this point in the history
  • Loading branch information
debarshiray committed May 13, 2020
1 parent 662bd89 commit ebd92b9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
package cmd

import (
"errors"
"fmt"
"os"
"os/exec"
"strings"
"syscall"

"github.com/containers/toolbox/pkg/utils"
"github.com/spf13/cobra"
Expand All @@ -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
}

Expand Down

0 comments on commit ebd92b9

Please sign in to comment.