Skip to content

Commit c76b0b5

Browse files
committed
Docs, clean-ups
1 parent 03514ca commit c76b0b5

File tree

7 files changed

+26
-16
lines changed

7 files changed

+26
-16
lines changed

klog/app/cli/args/misc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ type DiffArgs struct {
1313
Diff bool `name:"diff" short:"d" help:"Show difference between actual and should-total time."`
1414
}
1515

16+
// GetWarning returns a warning if the user applied entry-level filtering (partial
17+
// records) *and* requested to compute the should-total diff, as that may yield
18+
// nonsensical results.
1619
func (args *DiffArgs) GetWarning(filterArgs FilterArgs) service.UsageWarning {
1720
if args.Diff && filterArgs.hasPartialRecordsWithShouldTotal {
1821
return service.DiffEntryFilteringWarning

klog/app/cli/args/now.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ func (args *NowArgs) HadOpenRange() bool {
3434
return args.hadOpenRange
3535
}
3636

37+
// GetWarning warns the user that they specified the --now flag but there actually
38+
// weren’t any closable ranges in the data.
3739
func (args *NowArgs) GetWarning() service.UsageWarning {
3840
if args.Now && !args.hadOpenRange {
3941
return service.PointlessNowWarning

klog/app/cli/print.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (opt *Print) Help() string {
2525
Outputs data on the terminal, by default with syntax-highlighting turned on.
2626
Note that the output doesn’t resemble the file verbatim, but it may apply some minor formatting.
2727
28-
If run with filter flags, it only outputs those entries that match the filter clauses (i.e., you may see partial records).
28+
If run with filter flags, it only outputs those entries that match the filter clauses. E.g., when filtering for a tag that only appears particular entries, it will exclude all other entries from that record.
2929
3030
You can optionally also sort the records, or print out the total times for each record and entry.
3131
`

klog/app/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ var CONFIG_FILE_ENTRIES = []ConfigFileEntries[any]{
245245
"`OVERLAPPING_RANGES` (for time ranges that overlap), " +
246246
"`MORE_THAN_24H` (if there is a record with more than 24h total), " +
247247
"`POINTLESS_NOW` (when using --now without any open ranges), " +
248-
"`DIFF_ENTRY_FILTERING` (for combining --diff and entry-level filtering). " +
248+
"`ENTRY_FILTERED_DIFFING` (when combining --diff and entry-level filtering). " +
249249
"Multiple values must be separated by a comma, e.g.: `UNCLOSED_OPEN_RANGE, MORE_THAN_24H`.",
250250
Default: "If absent/empty, klog prints all available warnings.",
251251
},

klog/service/filter/filter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66

77
// Filter goes through a list of records and only keeps those that match the
88
// given predicate. The records may be returned partially, keeping only those
9-
// entries that match the predicate. The second return value indicates whether
10-
// there are partial records with ShouldTotal set, as this may yield nonsensical
11-
// results in a subsequent evaluation.
9+
// entries that match the predicate.
10+
// The second return value indicates whether there are partial records with a
11+
// should-total set, as this may yield nonsensical results in a subsequent evaluation.
1212
func Filter(p Predicate, rs []klog.Record) ([]klog.Record, bool) {
1313
var res []klog.Record
1414
hasPartialRecordsWithShouldTotal := false

klog/service/filter/filter_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import (
1111

1212
func sampleRecordsForQuerying() []klog.Record {
1313
rs, _, err := parser.NewSerialParser().Parse(`
14+
1999-12-29
15+
No tags here
16+
1417
1999-12-30
1518
Hello World #foo #first
1619
@@ -62,6 +65,7 @@ func TestQueryWithNoClauses(t *testing.T) {
6265
rs, hprws := Filter(And{}, sampleRecordsForQuerying())
6366
assert.False(t, hprws)
6467
assertResult(t, []expect{
68+
{klog.Ɀ_Date_(1999, 12, 29), []int{}},
6569
{klog.Ɀ_Date_(1999, 12, 30), []int{}},
6670
{klog.Ɀ_Date_(1999, 12, 31), []int{300}},
6771
{klog.Ɀ_Date_(2000, 1, 1), []int{15, 360, -30}},
@@ -101,22 +105,13 @@ func TestQueryWithBefore(t *testing.T) {
101105
}, sampleRecordsForQuerying())
102106
assert.False(t, hprws)
103107
assertResult(t, []expect{
108+
{klog.Ɀ_Date_(1999, 12, 29), []int{}},
104109
{klog.Ɀ_Date_(1999, 12, 30), []int{}},
105110
{klog.Ɀ_Date_(1999, 12, 31), []int{300}},
106111
{klog.Ɀ_Date_(2000, 1, 1), []int{15, 360, -30}},
107112
}, rs)
108113
}
109114

110-
func TestQueryWithTagOnEntries(t *testing.T) {
111-
rs, hprws := Filter(HasTag{klog.NewTagOrPanic("bar", "")}, sampleRecordsForQuerying())
112-
assert.True(t, hprws)
113-
assertResult(t, []expect{
114-
{klog.Ɀ_Date_(1999, 12, 31), []int{300}},
115-
{klog.Ɀ_Date_(2000, 1, 1), []int{360}},
116-
{klog.Ɀ_Date_(2000, 1, 3), []int{240, 180}},
117-
}, rs)
118-
}
119-
120115
func TestQueryWithTagOnOverallSummary(t *testing.T) {
121116
rs, hprws := Filter(HasTag{klog.NewTagOrPanic("foo", "")}, sampleRecordsForQuerying())
122117
assert.False(t, hprws)
@@ -128,6 +123,16 @@ func TestQueryWithTagOnOverallSummary(t *testing.T) {
128123
}, rs)
129124
}
130125

126+
func TestQueryWithTagOnEntries(t *testing.T) {
127+
rs, hprws := Filter(HasTag{klog.NewTagOrPanic("bar", "")}, sampleRecordsForQuerying())
128+
assert.True(t, hprws)
129+
assertResult(t, []expect{
130+
{klog.Ɀ_Date_(1999, 12, 31), []int{300}},
131+
{klog.Ɀ_Date_(2000, 1, 1), []int{360}},
132+
{klog.Ɀ_Date_(2000, 1, 3), []int{240, 180}},
133+
}, rs)
134+
}
135+
131136
func TestQueryWithTagOnEntriesAndInSummary(t *testing.T) {
132137
rs, hprws := Filter(And{[]Predicate{HasTag{klog.NewTagOrPanic("foo", "")}, HasTag{klog.NewTagOrPanic("bar", "")}}}, sampleRecordsForQuerying())
133138
assert.True(t, hprws)

klog/service/warning.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
Message: "You specified --now, but there was no open-ended time range",
2020
}
2121
DiffEntryFilteringWarning = UsageWarning{
22-
Name: "DIFF_ENTRY_FILTERING",
22+
Name: "ENTRY_FILTERED_DIFFING",
2323
Message: "Combining --diff and filtering at entry-level may yield nonsensical results",
2424
}
2525
)

0 commit comments

Comments
 (0)