Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
first steps
Browse files Browse the repository at this point in the history
Signed-off-by: Victor <[email protected]>
  • Loading branch information
victor-schumacher committed Oct 7, 2021
1 parent 5580033 commit 0628aeb
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
79 changes: 79 additions & 0 deletions pkg/cmd/uninstall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package cmd

import (
"errors"
"fmt"
"runtime"

"github.com/ZupIT/ritchie-cli/pkg/prompt"
"github.com/ZupIT/ritchie-cli/pkg/stream"
"github.com/spf13/cobra"
)

var (
ErrCannotUninstall = errors.New("cannot remove rit")
)

// uninstallCmd type for uninstall command.
type uninstallCmd struct {
inBool prompt.InputBool
file stream.FileRemover
}

// NewUninstallCmd creates a new cmd instance.
func NewUninstallCmd(
inBool prompt.InputBool,
file stream.FileRemover,
) *cobra.Command {
c := uninstallCmd{
inBool: inBool,
file: file,
}

cmd := &cobra.Command{
Use: "uninstall",
Short: "Uninstall rit",
Example: "rit uninstall",
RunE: c.runPrompt(),
ValidArgs: []string{""},
Args: cobra.OnlyValidArgs,
}

cmd.LocalFlags()

return cmd
}

func (c uninstallCmd) runPrompt() CommandRunnerFunc {
return func(cmd *cobra.Command, args []string) error {
sure, err := c.inBool.Bool("Are you sure", []string{"yes", "no"})
if err != nil {
fmt.Println(err)
}

if sure {
if err := c.uninstall(); err != nil {
fmt.Println(err)
}
}

return nil
}
}

func (c uninstallCmd) uninstall() error {
switch runtime.GOOS {
case "windows":
fmt.Println("later")
default:
if err := c.file.Remove("/usr/local/bin/rit"); err != nil {
return errors.New(
"Fail to uninstall\n" +
"Please try running this command again as root/Administrator\n" +
"Example: sudo rit uninstall",
)
}
}

return nil
}
2 changes: 2 additions & 0 deletions pkg/commands/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func Build() *cobra.Command {
metricsCmd := cmd.NewMetricsCmd(fileManager, inputList)
tutorialCmd := cmd.NewTutorialCmd(inputList, tutorialFindSetter)
renameCmd := cmd.NewRenameCmd()
uninstallCmd := cmd.NewUninstallCmd(inputBool, fileManager)

// level 2
setCredentialCmd := cmd.NewSetCredentialCmd(
Expand Down Expand Up @@ -289,6 +290,7 @@ func Build() *cobra.Command {
createCmd,
deleteCmd,
initCmd,
uninstallCmd,
listCmd,
setCmd,
showCmd,
Expand Down

0 comments on commit 0628aeb

Please sign in to comment.