Skip to content

Commit

Permalink
✔️🏁 Added logs flag for get command
Browse files Browse the repository at this point in the history
	[+] Added the corresponding test
	--> Issues related: #15, #16
  • Loading branch information
ChacaS0 committed Apr 4, 2018
1 parent fc433f8 commit 276a657
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion autostart.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

/home/archuser/Gitspace/gocode/bin/tempest start -t >>/home/archuser/.tempest.log 2>&1
$GOBIN/tempest start --shutup
33 changes: 33 additions & 0 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ package cmd

import (
"fmt"
"io/ioutil"

"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// gAge is true if the user wants to know the age set in config
var gAge bool

// allLogs tells if the user wants to see logs
var allLogs bool

// getCmd represents the get command
var getCmd = &cobra.Command{
Use: "get",
Expand Down Expand Up @@ -60,6 +65,32 @@ func init() {
// getCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

getCmd.Flags().BoolVarP(&gAge, "age", "a", false, "Use this if you want to know the age set in .tempest.yaml")
getCmd.Flags().BoolVarP(&allLogs, "logs", "l", false, "Use this flag to view all logs")
}

// getAllLogs handle the use of ``logs`` flag.
// We assume that ``allLogs`` is sets to true when calling this func.
func getAllLogs(args []string) error {
// var declare
var showShutup bool

//* Setup rights for shutup
if len(args) == 0 {
showShutup = true
}

//* Display Log Shutup
if is, err := IsDirectory(LogShutup); !is && err == nil && showShutup {
// Fetch the content of LogShutup
fileCtnt, errRF := ioutil.ReadFile(LogShutup)
if errRF != nil {
fmt.Println(redB(":: [ERROR]"), color.HiRedString("Could not read the file -_-\n\t->", LogShutup, "\n\t->", errRF))
}
fmt.Println(magB("=========================================== - [ShutupLogs] - ==================================================="))
fmt.Println(string(fileCtnt))
fmt.Println(magB("======================================== - [EOF - ShutupLogs] - ================================================"))
}
return nil
}

// printAnyIfSet displays the config set for the ones asked.
Expand All @@ -69,6 +100,8 @@ func printAnyIfSet(args []string) {
case gAge:
// Age A.K.A. the duration
fmt.Println(blueB("::"), whiteB("Age:"), getAge())
case allLogs:
getAllLogs(args)
default:
// help ?
getHelp()
Expand Down
29 changes: 29 additions & 0 deletions cmd/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package cmd

import (
"fmt"
"io/ioutil"
"testing"

"github.com/fatih/color"
"github.com/spf13/viper"
)

Expand All @@ -28,3 +30,30 @@ func TestGetAge(t *testing.T) {
}

}

// TestGetAllLogs is the test for getAllLogs(args []string){}.
// It should display all the logs available
func TestGetAllLogs(t *testing.T) {
var want string

headerShutup := magB("=========================================== - [ShutupLogs] - ===================================================")
footerShutup := magB("======================================== - [EOF - ShutupLogs] - ================================================")

fileCtnt, errRF := ioutil.ReadFile(LogShutup)
if errRF != nil {
fmt.Println(redB(":: [ERROR]"), color.HiRedString("Could not read the file -_-\n\t->", LogShutup, "\n\t->", errRF))
}

// what we want
want += fmt.Sprintln(headerShutup)
want += fmt.Sprintln(string(fileCtnt))
want += fmt.Sprintf(footerShutup)

got := captureStdout(func() {
getAllLogs([]string{})
})

if got != want {
t.Log("[FAIL]:: Result is different than expected:\n\t[GOT]\n", got, "\n\t[WANT]\n", want)
}
}
3 changes: 2 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ tempest start -t
}
// call purge
if errPurge := callPurge(allPaths); errPurge != nil {
fmt.Println(color.RedString("Sorry something went terribly wrong... Feels brah!\n"), errPurge)
// fmt.Println(color.RedString("Sorry something went terribly wrong... Feels brah!\n"), errPurge)
fmt.Println(color.HiYellowString("\n[!] Try to run:\n\t tempest list --fix"))
}
// fmt.Println("start called")
},
Expand Down

0 comments on commit 276a657

Please sign in to comment.