Skip to content

Commit 58e2cb9

Browse files
authored
Refactor and enhance klog today command (formerly klog now)
* Rename row labels and wrap end-time in parenthesis if there is no open range * Rename `klog now` to `klog today` * Restructure command * Don’t display signed value for grand total values * Cleanup * Add test for when end time is out of bounds * Update changelog
1 parent 9b51b1f commit 58e2cb9

File tree

8 files changed

+376
-272
lines changed

8 files changed

+376
-272
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Changelog (command line tool)
22

33
## v2.5
4-
- **[ FEATURE ]** Restructure output of `klog now`, especially when
5-
using the `--diff` flag
4+
- **[ BREAKING ]** Rename `klog now` to `klog today`; restructure the
5+
output, especially when using the `--diff`/`--now` flag
66
- **[ FEATURE ]** Use distinct exit codes for different error cases
77
- **[ FEATURE ]** Introduce `--quiet` flag to retrieve raw output
88
- **[ FEATURE ]** Extend help texts, improve error messages

src/app/cli/index.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package cli
22

3+
import (
4+
"errors"
5+
"klog/app"
6+
)
7+
38
type Cli struct {
49
// Evaluate
510
Print Print `cmd group:"Evaluate" help:"Pretty-prints records"`
611
Total Total `cmd group:"Evaluate" help:"Evaluates the total time"`
712
Report Report `cmd group:"Evaluate" help:"Prints a calendar report summarising all days"`
813
Tags Tags `cmd group:"Evaluate" help:"Prints total times aggregated by tags"`
9-
Now Now `cmd group:"Evaluate" help:"Show overview of the current day"`
14+
Today Today `cmd group:"Evaluate" help:"Evaluate current day"`
15+
Now Now `cmd group:"Evaluate" hidden help:"Show overview of the current day"`
1016

1117
// Manipulate
1218
Track Track `cmd group:"Manipulate" help:"Adds a new entry to a record"`
@@ -20,3 +26,12 @@ type Cli struct {
2026
Widget Widget `cmd group:"Misc" help:"Starts menu bar widget (MacOS only)"`
2127
Version Version `cmd group:"Misc" help:"Prints version info and check for updates"`
2228
}
29+
30+
// DEPRECATED
31+
type Now struct {
32+
Today
33+
}
34+
35+
func (opt *Now) Run(_ app.Context) error {
36+
return errors.New("`klog now` has been renamed to `klog today`. Note that the `--now` flag must be passed explicitly.")
37+
}

src/app/cli/now.go

Lines changed: 0 additions & 181 deletions
This file was deleted.

src/app/cli/now_test.go

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/app/cli/report.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (opt *Report) Run(ctx app.Context) error {
8787
}
8888
ctx.Print("\n")
8989
grandTotal := opt.NowArgs.Total(now, records...)
90-
ctx.Print(indentation + lib.Pad(9-len(grandTotal.ToStringWithSign())) + ctx.Serialiser().SignedDuration(grandTotal))
90+
ctx.Print(indentation + lib.Pad(9-len(grandTotal.ToString())) + ctx.Serialiser().Duration(grandTotal))
9191
if opt.Diff {
9292
grandShould := service.ShouldTotalSum(records...)
9393
ctx.Print(lib.Pad(10-len(grandShould.ToString())) + ctx.Serialiser().ShouldTotal(grandShould))

src/app/cli/report_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestReportOfRecords(t *testing.T) {
5353
Mar Tue 2. -8h2m
5454
Wed 3. 1h
5555
========
56-
+335h50m
56+
335h50m
5757
`, state.printBuffer)
5858
}
5959

@@ -77,7 +77,7 @@ func TestReportConsecutive(t *testing.T) {
7777
Sat 3.
7878
Sun 4. 3h
7979
========
80-
+4h
80+
4h
8181
`, state.printBuffer)
8282
}
8383

@@ -101,6 +101,6 @@ func TestReportWithDiff(t *testing.T) {
101101
Sun 8. 2h 5h30m! -3h30m
102102
Mon 9. 5h20m 2h19m! +3h1m
103103
===========================
104-
+15h20m 15h49m! -29m
104+
15h20m 15h49m! -29m
105105
`, state.printBuffer)
106106
}

0 commit comments

Comments
 (0)