Skip to content

Commit

Permalink
Forgot to add the file
Browse files Browse the repository at this point in the history
  • Loading branch information
Granjeon Alexandre committed Nov 23, 2021
1 parent 9a2a842 commit 3f38e70
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"io/ioutil"
"os"
"strings"
"time"

"github.com/gookit/color"
"github.com/jedib0t/go-pretty/v6/table"
)

func Status() {
files, err := ioutil.ReadDir(".gitplan/commits")
if err != nil || len(files) == 0 {
// Should never happen, but who knows
color.Error.Println("I guess you don't have any commit yet huh")
return
}
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"Date", "Branch", "Message"})
for _, file := range files {
if !strings.Contains(file.Name(), ".info") {
continue
}
content, err := os.ReadFile(".gitplan/commits/" + file.Name())
if err != nil {
return
}
fileContent := string(content)
s := strings.Split(fileContent, "\n")
date, branchName, message := humanDate(s[0]), s[1], s[2]

t.AppendRow(table.Row{date, branchName, message})
}
t.Render()
}

func humanDate(date string) string {
humanDate, _ := time.Parse(time.Stamp, date)

return humanDate.Format("2006-01-02 15:04")
}

0 comments on commit 3f38e70

Please sign in to comment.