From fe3fa4c2d0718d16fd17b23718ccd5acbe306523 Mon Sep 17 00:00:00 2001 From: Shlok Patel Date: Sun, 28 Nov 2021 21:59:17 +0530 Subject: [PATCH] UI changes --- cmd/get.go | 4 ++-- cmd/list.go | 7 +++---- cmd/rm.go | 21 +++++++++++++++++---- styles/styles.go | 10 +++++----- utils/validate/validate.go | 19 +++++++++++++++++++ 5 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 utils/validate/validate.go diff --git a/cmd/get.go b/cmd/get.go index 8e08187..9249265 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -32,13 +32,13 @@ func getGithub(args []string) { targetPath := path.Join(currDir, args[1]) if osutil.Exists(path.Join(currDir, args[1])) { - fmt.Println(styles.InitError.Render("Directory with similar name already exsists !")) + fmt.Println(styles.Error.Render("Directory with similar name already exsists !")) os.Exit(1) } if err := git.CloneRepo(targetPath, git.CloneOptions{ URL: host.URL(args[0]), }); err != nil { - fmt.Println(styles.InitError.Render("There was error cloning the repo"), args[0]) + fmt.Println(styles.Error.Render("There was error cloning the repo"), args[0]) } } diff --git a/cmd/list.go b/cmd/list.go index b0296f9..f323dd6 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -19,7 +19,6 @@ var listCmd = &cobra.Command{ Use: "list", Short: "List all the saved bare", Run: func(cmd *cobra.Command, args []string) { - if len(args) == 0 { ListBare() } else { @@ -29,13 +28,13 @@ var listCmd = &cobra.Command{ } func ListBare() { - fmt.Println(styles.InitStyle.Render("Lists of all the bare")) + fmt.Println(styles.InitStyle.Render("~ bare list ~")) barePath := filepath.Join(os.Getenv("HOME"), ".bare") fis, err := ioutil.ReadDir(barePath) if err != nil { - fmt.Println(styles.InitError.Render("Error reading directory from ~/.bare")) + fmt.Println(styles.Error.Render("Error reading directory from ~/.bare")) os.Exit(1) } @@ -51,7 +50,7 @@ func ListBare() { } func ListFileWalk(bareName string) { - fmt.Println(styles.InitStyle.Render("Lists of all the files in"), styles.InitSuccess.Render(bareName)) + fmt.Println(styles.InitStyle.Render("Lists of all the files in"), styles.Success.Render(bareName)) barePath := filepath.Join(os.Getenv("HOME"), ".bare", bareName) printDirectory(barePath, 0) } diff --git a/cmd/rm.go b/cmd/rm.go index 3be2304..494b544 100644 --- a/cmd/rm.go +++ b/cmd/rm.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/spf13/cobra" ) @@ -21,18 +22,30 @@ var rmCmd = &cobra.Command{ if len(args) >= 1 { rmBare(args) } else { - fmt.Println(styles.InitError.Render("Not enought arguments")) + fmt.Println(styles.Error.Render("Not enought arguments")) } }, } func rmBare(delBares []string) { - fmt.Println(styles.InitStyle.Render("Bare rm")) + fmt.Println(styles.InitStyle.Render("~ bare rm ~")) barePath := filepath.Join(os.Getenv("HOME"), ".bare") + deletedBare := []string{} for _, bare := range delBares { if osutil.Exists(filepath.Join(barePath, bare)) { - fmt.Println(styles.InitError.Render("[Deleting] "), bare) - os.RemoveAll(filepath.Join(barePath, bare)) + fmt.Println(styles.StatusError.Render("X"), bare) + err := os.RemoveAll(filepath.Join(barePath, bare)) + if err != nil { + fmt.Println(styles.Error.Render("[Error] There was problem removing"), bare) + os.Exit(1) + } + deletedBare = append(deletedBare, bare) + } else { + fmt.Println(styles.Warning.Render("Bare does not exsist!"), bare) } } + if len(deletedBare) > 0 { + fmt.Println(styles.Success.Render("[Success] successfully removed"), strings.Trim(fmt.Sprint(deletedBare), "[]")) + } + } diff --git a/styles/styles.go b/styles/styles.go index 686b23e..7d61c16 100644 --- a/styles/styles.go +++ b/styles/styles.go @@ -7,15 +7,12 @@ import "github.com/charmbracelet/lipgloss" var InitStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("12")) -var InitError = lipgloss.NewStyle(). +var Error = lipgloss.NewStyle(). Foreground(lipgloss.Color("1")) -var InitSuccess = lipgloss.NewStyle(). +var Success = lipgloss.NewStyle(). Foreground(lipgloss.Color("#30da00")) -var AddFileStlyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("#b600da")) - var Warning = lipgloss.NewStyle().Foreground(lipgloss.Color("13")) var PromptStyle = lipgloss.NewStyle(). @@ -26,3 +23,6 @@ var StatusSuccess = lipgloss.NewStyle().Bold(true). var StatusPrompt = lipgloss.NewStyle().Bold(true). Foreground(lipgloss.Color("#00BDFF")) + +var StatusError = lipgloss.NewStyle().Bold(true). + Foreground(lipgloss.Color("#FF3A3A")) diff --git a/utils/validate/validate.go b/utils/validate/validate.go new file mode 100644 index 0000000..c57950f --- /dev/null +++ b/utils/validate/validate.go @@ -0,0 +1,19 @@ +package validate + +import "errors" + +var ( + ErrUnexpectedArgs = errors.New("Unexpected arguments") + ErrNotEnoughArgs = errors.New("Not enough arguments") +) + +func ValidateArgCount(expectedArgNo, argNo int) error { + switch { + case expectedArgNo < argNo: + return ErrUnexpectedArgs + case expectedArgNo > argNo: + return ErrNotEnoughArgs + } + + return nil +}