Skip to content

Commit

Permalink
chore: add gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Aug 26, 2024
1 parent e16a500 commit b9009d4
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 64 deletions.
9 changes: 9 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
linters:
enable:
- errcheck
- gofumpt
- gosimple
- govet
- ineffassign
- staticcheck
- unused
1 change: 0 additions & 1 deletion cmd/db_migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

func TestMigrationsAreSetupCorrectly(t *testing.T) {

migrations := getMigrations()
for i := 2; i <= latestDBVersion; i++ {
m, ok := migrations[i]
Expand Down
1 change: 0 additions & 1 deletion internal/ui/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const (

func ShowActiveTask(db *sql.DB, writer io.Writer, template string) {
activeTaskDetails, err := fetchActiveTaskFromDB(db)

if err != nil {
fmt.Fprintf(os.Stdout, "Something went wrong:\n%s", err)
os.Exit(1)
Expand Down
5 changes: 2 additions & 3 deletions internal/ui/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ func toggleTracking(db *sql.DB,
taskId int,
beginTs time.Time,
endTs time.Time,
comment string) tea.Cmd {
comment string,
) tea.Cmd {
return func() tea.Msg {

row := db.QueryRow(`
SELECT id, task_id
FROM task_log
Expand Down Expand Up @@ -73,7 +73,6 @@ func insertManualEntry(db *sql.DB, taskId int, beginTS time.Time, endTS time.Tim
func fetchActiveTask(db *sql.DB) tea.Cmd {
return func() tea.Msg {
activeTaskDetails, err := fetchActiveTaskFromDB(db)

if err != nil {
return activeTaskFetchedMsg{err: err}
}
Expand Down
1 change: 0 additions & 1 deletion internal/ui/date_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ const (
)

func getTSRelative(ts time.Time, reference time.Time) tsRelative {

if ts.Sub(reference) > 0 {
return tsFromFuture
}
Expand Down
7 changes: 0 additions & 7 deletions internal/ui/date_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,22 @@ func TestParseDateDuration(t *testing.T) {
} else {
assert.False(t, ok)
}

})
}
}

func TestGetTimePeriod(t *testing.T) {
now, err := time.ParseInLocation(string(timeFormat), "2024/06/20 20:00", time.Local)

if err != nil {
t.Fatalf("error setting up the test: time is not valid: %s", err)
}

nowME, err := time.ParseInLocation(string(timeFormat), "2024/05/31 20:00", time.Local)

if err != nil {
t.Fatalf("error setting up the test: time is not valid: %s", err)
}

nowMB, err := time.ParseInLocation(string(timeFormat), "2024/06/01 20:00", time.Local)

if err != nil {
t.Fatalf("error setting up the test: time is not valid: %s", err)
}
Expand Down Expand Up @@ -214,10 +210,8 @@ func TestGetTimePeriod(t *testing.T) {
} else {
assert.Equal(t, tt.err, err)
}

})
}

}

func TestGetTSRelative(t *testing.T) {
Expand Down Expand Up @@ -266,5 +260,4 @@ func TestGetTSRelative(t *testing.T) {
assert.Equal(t, tt.expected, got)
})
}

}
34 changes: 16 additions & 18 deletions internal/ui/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package ui

import "fmt"

var (
helpText = fmt.Sprintf(` %s
var helpText = fmt.Sprintf(` %s
%s
%s
Expand All @@ -20,8 +19,8 @@ var (
%s
%s
`,
helpHeaderStyle.Render("\"hours\" Reference Manual"),
helpSectionStyle.Render(`
helpHeaderStyle.Render("\"hours\" Reference Manual"),
helpSectionStyle.Render(`
"hours" has 6 views:
- Tasks List View Shows active tasks
- Task Management View Shows a form to create/update tasks
Expand All @@ -30,26 +29,26 @@ var (
- Task Log Entry View Shows a form to save/update a task log entry
- Help View (this one)
`),
helpHeaderStyle.Render("Keyboard Shortcuts"),
helpHeaderStyle.Render("General"),
helpSectionStyle.Render(`
helpHeaderStyle.Render("Keyboard Shortcuts"),
helpHeaderStyle.Render("General"),
helpSectionStyle.Render(`
1 Switch to Tasks List View
2 Switch to Task Logs List View
3 Switch to Inactive Tasks List View
<tab> Go to next view/form entry
<shift+tab> Go to previous view/form entry
? Show help view
`),
helpHeaderStyle.Render("General List Controls"),
helpSectionStyle.Render(`
helpHeaderStyle.Render("General List Controls"),
helpSectionStyle.Render(`
k/<Up> Move cursor up
j/<Down> Move cursor down
h<Left> Go to previous page
l<Right> Go to next page
<ctrl+r> Refresh list
`),
helpHeaderStyle.Render("Task List View"),
helpSectionStyle.Render(`
helpHeaderStyle.Render("Task List View"),
helpSectionStyle.Render(`
a Add a task
u Update task details
s Start/stop recording time on a task; stopping will open up the "Task Log Entry View"
Expand All @@ -58,21 +57,20 @@ var (
<ctrl+t> Go to currently tracked item
<ctrl+d> Deactivate task
`),
helpHeaderStyle.Render("Task Logs List View"),
helpSectionStyle.Render(`
helpHeaderStyle.Render("Task Logs List View"),
helpSectionStyle.Render(`
<ctrl+d> Delete task log entry
`),
helpHeaderStyle.Render("Inactive Task List View"),
helpSectionStyle.Render(`
helpHeaderStyle.Render("Inactive Task List View"),
helpSectionStyle.Render(`
<ctrl+d> Activate task
`),
helpHeaderStyle.Render("Task Log Entry View"),
helpSectionStyle.Render(`
helpHeaderStyle.Render("Task Log Entry View"),
helpSectionStyle.Render(`
enter Save entered details for the task log
k Move timestamp backwards by one minute
j Move timestamp forwards by one minute
K Move timestamp backwards by five minutes
J Move timestamp forwards by five minutes
`),
)
)
1 change: 0 additions & 1 deletion internal/ui/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func InitialModel(db *sql.DB) model {
}

func initialRecordsModel(typ recordsType, db *sql.DB, start, end time.Time, plain bool, period string, numDays int, initialData string) recordsModel {

return recordsModel{
typ: typ,
db: db,
Expand Down
3 changes: 0 additions & 3 deletions internal/ui/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func RenderTaskLog(db *sql.DB, writer io.Writer, plain bool, period string, inte
}

ts, err := getTimePeriod(period, time.Now(), false)

if err != nil {
fmt.Printf("error: %s\n", err)
os.Exit(1)
Expand Down Expand Up @@ -52,9 +51,7 @@ func RenderTaskLog(db *sql.DB, writer io.Writer, plain bool, period string, inte
}

func renderTaskLog(db *sql.DB, start, end time.Time, limit int, plain bool) (string, error) {

entries, err := fetchTLEntriesBetweenTSFromDB(db, start, end, limit)

if err != nil {
return "", err
}
Expand Down
21 changes: 0 additions & 21 deletions internal/ui/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import (
)

func insertNewTLInDB(db *sql.DB, taskId int, beginTs time.Time) error {

stmt, err := db.Prepare(`
INSERT INTO task_log (task_id, begin_ts, active)
VALUES (?, ?, ?);
`)

if err != nil {
return err
}
Expand All @@ -28,12 +26,10 @@ VALUES (?, ?, ?);
}

func updateTLBeginTSInDB(db *sql.DB, beginTs time.Time) error {

stmt, err := db.Prepare(`
UPDATE task_log SET begin_ts=?
WHERE active is true;
`)

if err != nil {
return err
}
Expand All @@ -48,7 +44,6 @@ WHERE active is true;
}

func deleteActiveTLInDB(db *sql.DB) error {

stmt, err := db.Prepare(`
DELETE FROM task_log
WHERE active=true;
Expand All @@ -64,7 +59,6 @@ WHERE active=true;
}

func updateActiveTLInDB(db *sql.DB, taskLogId int, taskId int, beginTs, endTs time.Time, secsSpent int, comment string) error {

tx, err := db.Begin()
if err != nil {
return err
Expand Down Expand Up @@ -118,7 +112,6 @@ WHERE id = ?;
}

func insertManualTLInDB(db *sql.DB, taskId int, beginTs time.Time, endTs time.Time, comment string) error {

secsSpent := int(endTs.Sub(beginTs).Seconds())
tx, err := db.Begin()
if err != nil {
Expand Down Expand Up @@ -167,7 +160,6 @@ WHERE id = ?;
}

func fetchActiveTaskFromDB(db *sql.DB) (activeTaskDetails, error) {

row := db.QueryRow(`
SELECT t.id, t.summary, tl.begin_ts
FROM task_log tl left join task t on tl.task_id = t.id
Expand All @@ -191,7 +183,6 @@ WHERE tl.active=true;
}

func insertTaskInDB(db *sql.DB, summary string) error {

stmt, err := db.Prepare(`
INSERT into task (summary, active, created_at, updated_at)
VALUES (?, true, ?, ?);
Expand All @@ -203,15 +194,13 @@ VALUES (?, true, ?, ?);

now := time.Now().UTC()
_, err = stmt.Exec(summary, now, now)

if err != nil {
return err
}
return nil
}

func updateTaskInDB(db *sql.DB, id int, summary string) error {

stmt, err := db.Prepare(`
UPDATE task
SET summary = ?,
Expand All @@ -224,15 +213,13 @@ WHERE id = ?
defer stmt.Close()

_, err = stmt.Exec(summary, time.Now().UTC(), id)

if err != nil {
return err
}
return nil
}

func updateTaskActiveStatusInDB(db *sql.DB, id int, active bool) error {

stmt, err := db.Prepare(`
UPDATE task
SET active = ?,
Expand All @@ -245,15 +232,13 @@ WHERE id = ?
defer stmt.Close()

_, err = stmt.Exec(active, time.Now().UTC(), id)

if err != nil {
return err
}
return nil
}

func updateTaskDataFromDB(db *sql.DB, t *task) error {

row := db.QueryRow(`
SELECT secs_spent, updated_at
FROM task
Expand All @@ -271,7 +256,6 @@ WHERE id=?;
}

func fetchTasksFromDB(db *sql.DB, active bool, limit int) ([]task, error) {

var tasks []task

rows, err := db.Query(`
Expand Down Expand Up @@ -307,7 +291,6 @@ LIMIT ?;
}

func fetchTLEntriesFromDB(db *sql.DB, desc bool, limit int) ([]taskLogEntry, error) {

var logEntries []taskLogEntry

var order string
Expand Down Expand Up @@ -352,7 +335,6 @@ LIMIT ?;
}

func fetchTLEntriesBetweenTSFromDB(db *sql.DB, beginTs, endTs time.Time, limit int) ([]taskLogEntry, error) {

var logEntries []taskLogEntry

rows, err := db.Query(`
Expand Down Expand Up @@ -390,7 +372,6 @@ ORDER by tl.begin_ts ASC LIMIT ?;
}

func fetchStatsFromDB(db *sql.DB, limit int) ([]taskReportEntry, error) {

rows, err := db.Query(`
SELECT tl.task_id, t.summary, COUNT(tl.id) as num_entries, t.secs_spent
from task_log tl
Expand Down Expand Up @@ -424,7 +405,6 @@ limit ?;
}

func fetchStatsBetweenTSFromDB(db *sql.DB, beginTs, endTs time.Time, limit int) ([]taskReportEntry, error) {

rows, err := db.Query(`
SELECT tl.task_id, t.summary, COUNT(tl.id) as num_entries, SUM(tl.secs_spent) AS secs_spent
FROM task_log tl
Expand Down Expand Up @@ -459,7 +439,6 @@ LIMIT ?;
}

func fetchReportBetweenTSFromDB(db *sql.DB, beginTs, endTs time.Time, limit int) ([]taskReportEntry, error) {

rows, err := db.Query(`
SELECT tl.task_id, t.summary, COUNT(tl.id) as num_entries, SUM(tl.secs_spent) AS secs_spent
FROM task_log tl
Expand Down
1 change: 1 addition & 0 deletions internal/ui/render_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (t *task) updateDesc() {

t.desc = fmt.Sprintf("%s %s", RightPadTrim(lastUpdated, 60, true), timeSpent)
}

func (tl *taskLogEntry) updateTitle() {
tl.title = Trim(tl.comment, 60)
}
Expand Down
2 changes: 0 additions & 2 deletions internal/ui/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func RenderReport(db *sql.DB, writer io.Writer, plain bool, period string, agg b
fullWeek = true
}
ts, err := getTimePeriod(period, time.Now(), fullWeek)

if err != nil {
fmt.Printf("error: %s\n", err)
os.Exit(1)
Expand Down Expand Up @@ -192,7 +191,6 @@ func getReport(db *sql.DB, start time.Time, numDays int, plain bool) (string, er
}

func getReportAgg(db *sql.DB, start time.Time, numDays int, plain bool) (string, error) {

day := start
var nextDay time.Time

Expand Down
Loading

0 comments on commit b9009d4

Please sign in to comment.