Skip to content

Commit

Permalink
Improvement of the rm command (#21) (#25)
Browse files Browse the repository at this point in the history
* ✔️ Mispells fixes

 On branch devel
 Changes to be committed:
	modified:   cmd/init_test.go
	modified:   cmd/list.go
	modified:   cmd/list_test.go
	modified:   cmd/rm_test.go
	modified:   cmd/start_test.go

* 🚧 Work on rework of rm command starts -- bad

 Issues related:
 	-> #21 Improve ``rm`` command

 On branch dev-enhancement-rm
 Changes to be committed:
	modified:   cmd/rm.go

* 💊 Fixed missspelling

 On branch dev-enhancement-rm
 Changes to be committed:
	modified:   cmd/init_test.go
	modified:   cmd/list.go
	modified:   cmd/rm.go
	modified:   cmd/rm_test.go

* ✔️🏁 processArgsRm added + tests

 Issues related:
 	-> #21
 	-> #16
 	-> #9

 On branch dev-enhancement-rm
 Changes to be committed:
	modified:   cmd/init_test.go
	modified:   cmd/rm.go
	modified:   cmd/rm_test.go

* ✔️🏁 New feature for rm
	-> Added & adapted tests only for the ones impacted by those changes

 Issues related:
 	-> #21
 	-> #16

 On branch dev-enhancement-rm
 Changes to be committed:
	modified:   cmd/rm.go
	modified:   cmd/rm_test.go
	modified:   cmd/root.go

* 💻🏁 Added test for rm.go:simpleDelAllString()
	-> Few changes (variadic params instead of slice)
	-> Some update for the ``$HOME`` on Windows

 Issues related:
 	-> #21
 	-> #16
 	-> #9

 On branch dev-enhancement-rm
 Changes to be committed:
	modified:   cmd/purge.go
	modified:   cmd/rm.go
	modified:   cmd/rm_test.go
	modified:   cmd/root.go

* ✔️🏁 Added handler for ``*`` wildcard as argument
	-> Tests, were adapted for that

 Issues related:
 	-> #21

 On branch dev-enhancement-rm
 Changes to be committed:
	modified:   cmd/rm.go
	modified:   cmd/rm_test.go

* 📝 Update of usage for ``rm`` and deletion of deprecated stuff

 Issues related:
 	-> #21
 	-> #19

 On branch dev-enhancement-rm
 Changes to be committed:
	modified:   cmd/rm.go
  • Loading branch information
ChacaS0 committed Mar 31, 2018
1 parent bf1ab1d commit adee1cc
Show file tree
Hide file tree
Showing 8 changed files with 418 additions and 68 deletions.
54 changes: 53 additions & 1 deletion cmd/init_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"bytes"
"io"
"os"
"testing"

Expand Down Expand Up @@ -173,9 +175,42 @@ func fbTestTempestcf(t *testing.T, tempestcfbup string) {
Tempestcf = tempestcfbup
}

// SameSlices checks equality between two slices
// SameSlices checks equality between two slices of string
// returns true if they are identiques
func SameSlices(a, b []string) bool {
if a == nil && nil == b {
return true
}

if len(a) == 0 && len(b) == 0 {
return true
}

if len(a) != len(b) {
return false
}

b = b[:len(a)]
for i, v := range a {
if v != b[i] {
return false
}
}

return true
}

// SameSlicesInt checks equality between two slices of int
// returns true if they are identiques
func SameSlicesInt(a, b []int) bool {
if a == nil && nil == b {
return true
}

if len(a) == 0 && len(b) == 0 {
return true
}

if len(a) != len(b) {
return false
}
Expand All @@ -189,3 +224,20 @@ func SameSlices(a, b []string) bool {

return true
}

// captureStdout returns the output of a function
// not thread safe
func captureStdout(f func()) string {
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w

f()

w.Close()
os.Stdout = old

var buf bytes.Buffer
io.Copy(&buf, r)
return buf.String()
}
14 changes: 7 additions & 7 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Short: "Lists all the paths submitted to TEMPest.",
Long: `All the paths set for TEMPest.
Short: "Lists all the targets submitted to TEMPest.",
Long: `All the targets set for TEMPest.
They follow this pattern:
<IndexPath> <Path>
Expand All @@ -48,7 +48,7 @@ The IndexPath can then be used to select the path
`,
Run: func(cmd *cobra.Command, args []string) {
if errLi := printList(); errLi != nil {
fmt.Println(color.HiRedString("Could not list paths, sorry bra!", errLi))
fmt.Println(color.HiRedString("Could not list targets, sorry bra!", errLi))
}
},
}
Expand Down Expand Up @@ -78,16 +78,16 @@ func printList() error {
if errSliced != nil {
// Just a small enhancement of the "no paths set yet" display
if errSliced.Error() == "empty" {
fmt.Println(color.HiMagentaString(":: No path set yet\n:: Suggestion - Run: \n\ttempest help add\nFor more information about adding paths!"))
fmt.Println(color.HiMagentaString(":: No target set yet\n:: Suggestion - Run: \n\ttempest help add\nFor more information about adding targets!"))
return nil
}
return errSliced
}

// color.Red(fmt.Sprintf("%d", len(ctntSlice)))
if len(ctntSlice) >= 1 {
fmt.Println(color.HiYellowString("Current paths currently having \"fun\" with TEMPest:\n"))
fmt.Println(color.HiYellowString("Index\t| Path"))
fmt.Println(color.HiYellowString("Current targets currently having \"fun\" with TEMPest:\n"))
fmt.Println(color.HiYellowString("Index\t| Target"))
// fmt.Println(color.HiYellowString("--------------------------------------------------"))
}

Expand All @@ -97,7 +97,7 @@ func printList() error {
case i < len(aPath):
fmt.Println(color.HiYellowString(fmt.Sprintf("%d\t|", i)), aPath)
case i == 0:
fmt.Println(color.HiMagentaString("No path set yet\nSuggestion - Run: \n\ttempest help add\nFor more information about adding paths!"))
fmt.Println(color.HiMagentaString("No target set yet\nSuggestion - Run: \n\ttempest help add\nFor more information about adding targets!"))
}
}
return nil
Expand Down
23 changes: 2 additions & 21 deletions cmd/list_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cmd

import (
"bytes"
"io"
"os"
"testing"
)
Expand Down Expand Up @@ -68,7 +66,7 @@ func TestPrintList(t *testing.T) {
})

// Verify output
wantedOutput := ":: No path set yet\n:: Suggestion - Run: \n\ttempest help add\nFor more information about adding paths!\n"
wantedOutput := ":: No target set yet\n:: Suggestion - Run: \n\ttempest help add\nFor more information about adding targets!\n"
if wantedOutput != emptyOutput {
t.Log("[FAIL]:: printList() failed to process empty .tempestcf\n\t-> Expected:\n\t", wantedOutput, "\n\t-> Got:\n\t", emptyOutput)
t.Fail()
Expand All @@ -95,7 +93,7 @@ func TestPrintList(t *testing.T) {
})

// Verify output of printList()
wantedOutput = "Current paths currently having \"fun\" with TEMPest:\n\nIndex\t| Path\n0\t| " + conf.Gobin + "\n1\t| " + conf.Gopath + "\n"
wantedOutput = "Current targets currently having \"fun\" with TEMPest:\n\nIndex\t| Target\n0\t| " + conf.Gobin + "\n1\t| " + conf.Gopath + "\n"
if actualOutput != wantedOutput {
t.Log("[FAIL]:: The output of printList() was quite unexpected! Wow!\n\t-> ActualOutput:\n\t", actualOutput, "\n\t-> Wanted:\n\t", wantedOutput)
t.Fail()
Expand All @@ -104,20 +102,3 @@ func TestPrintList(t *testing.T) {
// Fallback
fbTestTempestcf(t, tempestcfbup)
}

// captureStdout returns the output of a function
// not thread safe
func captureStdout(f func()) string {
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w

f()

w.Close()
os.Stdout = old

var buf bytes.Buffer
io.Copy(&buf, r)
return buf.String()
}
2 changes: 1 addition & 1 deletion cmd/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func deleteAllStr(path string, targets []os.FileInfo, testMode bool) error {
func deleteAllInt(index int, testMode bool) error {
allPaths, errPaths := getPaths()
if errPaths != nil {
color.Red("::Error while reading .tempestcf")
color.Red(":: Error while reading .tempestcf")
return errPaths
}
if index >= 0 && index < len(allPaths) {
Expand Down
Loading

0 comments on commit adee1cc

Please sign in to comment.