Skip to content

Commit

Permalink
Added listing column "created_at"
Browse files Browse the repository at this point in the history
  • Loading branch information
kakakakakku committed Mar 25, 2016
1 parent 267c364 commit 80ff421
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions command/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"strconv"
"time"

"github.com/codegangsta/cli"
"github.com/olekukonko/tablewriter"
Expand All @@ -20,9 +21,9 @@ func CmdList(c *cli.Context) {

var s string
if isAllMode == "true" {
s = "SELECT id, title, is_done FROM todos"
s = "SELECT id, title, is_done, created_at FROM todos"
} else {
s = "SELECT id, title, is_done FROM todos WHERE is_done = 0"
s = "SELECT id, title, is_done, created_at FROM todos WHERE is_done = 0"
}

db, err := sql.Open("sqlite3", dbPath())
Expand All @@ -43,13 +44,14 @@ func CmdList(c *cli.Context) {
var id int
var title string
var isDone int
rows.Scan(&id, &title, &isDone)
data = append(data, []string{strconv.Itoa(id), title, doneLabel(isDone)})
var createdAt int64
rows.Scan(&id, &title, &isDone, &createdAt)
data = append(data, []string{strconv.Itoa(id), title, doneLabel(isDone), dateForView(createdAt)})
}

if len(data) > 0 {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"No", "Title", "Status"})
table.SetHeader([]string{"No", "Title", "Status", "Created"})
table.SetBorder(true)
table.AppendBulk(data)
table.Render()
Expand All @@ -62,3 +64,7 @@ func doneLabel(isDone int) string {
}
return "Done"
}

func dateForView(at int64) string {
return time.Unix(at, 0).Format("2006-01-02 15:04:05")
}

0 comments on commit 80ff421

Please sign in to comment.