Skip to content

Commit

Permalink
Refactored about command to pull the data
Browse files Browse the repository at this point in the history
  • Loading branch information
bovem committed Jan 16, 2024
1 parent 569fdac commit b12a375
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion cmd/about.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/bovem/brag/utils"
"github.com/spf13/cobra"
"strings"
"fmt"
)

var timeFrame string
Expand All @@ -21,7 +22,8 @@ The time period has to be specified in any of the following formats
* today/yesterday/last-week/last-month (brag about last-week/brag about yesterday)
`,
Run: func(cmd *cobra.Command, args []string) {
utils.Bragging(strings.Join(args, " "))
brags := utils.Bragging(strings.Join(args, " "))
fmt.Println(brags)
},
}

Expand Down
16 changes: 10 additions & 6 deletions utils/bragAbout.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"io/ioutil"
)

func Bragging(timeFrame string)(){
func Bragging(timeFrame string)(string){
bragDocDirLocation := os.Getenv("BRAG_DOCS_LOC")
currentTime := time.Now()
currentYear := strconv.Itoa(currentTime.Year())
Expand Down Expand Up @@ -56,10 +56,12 @@ func Bragging(timeFrame string)(){
}

startBraggingFrom := currentTime.AddDate(-numYear, -numMonth, -numDay)
LoopOverFileRange(currentYearDir, startBraggingFrom, endBraggingAt)
fileContents := LoopOverFileRange(currentYearDir, startBraggingFrom, endBraggingAt)
return fileContents
}

func LoopOverFileRange(fileDirectory string, startTime time.Time, endTime time.Time)(){
func LoopOverFileRange(fileDirectory string, startTime time.Time, endTime time.Time)(string){
var fileContents string
tomorrow := endTime.AddDate(0, 0, 1)
curDoc:=startTime

Expand All @@ -75,15 +77,17 @@ func LoopOverFileRange(fileDirectory string, startTime time.Time, endTime time.T
documentContent, err := ioutil.ReadFile(currentDocName)
if err!=nil {
fmt.Printf("Failed to open file: %s\n", currentDocName)
return
continue
}
//documentContentStr := strings.Replace(string(documentContent),
// "# Bragging Items", "", -1)
//documentContentStr = strings.Replace(documentContentStr,
// "\n", "", 1)
fmt.Println(currentDateStr)
fmt.Printf("%s\n", string(documentContent))
fileContents += fmt.Sprintf("%s\n", currentDateStr)
fileContents += fmt.Sprintf("%s\n", string(documentContent))
}
curDoc = curDoc.AddDate(0, 0, 1)
}

return fileContents
}

0 comments on commit b12a375

Please sign in to comment.