Skip to content

Commit

Permalink
Merge branch 'main' into colour-theme-basic
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaen committed Aug 17, 2024
2 parents ad3514d + 474d5df commit 2f269dc
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 115 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: CI
on: [push, pull_request]
env:
GO_VERSION: '1.22'
STATIC_CHECK_VERSION: '2023.1.6'
GO_VERSION: '1.23'
STATIC_CHECK_VERSION: '2024.1.1'
COUNT_LOC_DOCKER_IMAGE: 'aldanial/cloc:1.98'
jobs:
statistics:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
description: 'Release id (tag name)'
required: true
env:
GO_VERSION: '1.22'
GO_VERSION: '1.23'
jobs:
create_release:
name: Create release draft
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module github.com/jotaen/klog

go 1.22
go 1.23

require (
cloud.google.com/go v0.112.0
github.com/alecthomas/kong v0.8.1
cloud.google.com/go v0.115.1
github.com/alecthomas/kong v0.9.0
github.com/jotaen/genie v0.0.1
github.com/jotaen/kong-completion v0.0.6
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/posener/complete v1.2.3
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
)

require (
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cloud.google.com/go v0.112.0 h1:tpFCD7hpHFlQ8yPwT3x+QeXqc2T6+n6T+hmABHfDUSM=
cloud.google.com/go v0.112.0/go.mod h1:3jEEVwZ/MHU4djK5t5RHuKOA/GbLddgTdVubX1qnPD4=
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
github.com/alecthomas/assert/v2 v2.1.0/go.mod h1:b/+1DI2Q6NckYi+3mXyH3wFb8qG37K/DuK80n7WefXA=
github.com/alecthomas/kong v0.8.1 h1:acZdn3m4lLRobeh3Zi2S2EpnXTd1mOL6U7xVml+vfkY=
github.com/alecthomas/kong v0.8.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
github.com/alecthomas/repr v0.1.0/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
cloud.google.com/go v0.115.1 h1:Jo0SM9cQnSkYfp44+v+NQXHpcHqlnRJk2qxh6yvxxxQ=
cloud.google.com/go v0.115.1/go.mod h1:DuujITeaufu3gL68/lOFIirVNJwQeyf5UXyi+Wbgknc=
github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/kong v0.9.0 h1:G5diXxc85KvoV2f0ZRVuMsi45IrBgx9zDNGNj165aPA=
github.com/alecthomas/kong v0.9.0/go.mod h1:Y47y5gKfHp1hDc7CH7OeXgLIpp+Q2m1Ni0L5s3bI8Os=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -33,8 +33,8 @@ github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab h1:ZjX6I48eZSFetP
github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab/go.mod h1:/PfPXh0EntGc3QAAyUaviy4S9tzy4Zp0e2ilq4voC6E=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
74 changes: 3 additions & 71 deletions klog/app/cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
)

type Start struct {
SummaryText klog.EntrySummary `name:"summary" short:"s" placeholder:"TEXT" help:"Summary text for this entry."`
Resume bool `name:"resume" short:"R" help:"Take over summary of last entry (if applicable). If the target record is new or empty, it looks at the previous record."`
ResumeNth int `name:"resume-nth" short:"N" help:"Take over summary of nth entry. If INT is positive, it counts from the start (beginning with '1'); if negative, it counts from the end (beginning with '-1')"`
util.SummaryArgs
util.AtDateAndTimeArgs
util.NoStyleArgs
util.WarnArgs
Expand All @@ -22,6 +20,7 @@ type Start struct {
func (opt *Start) Help() string {
return `
This appends a new open-ended entry to the record.
By default, it uses the record at today’s date for the new entry, or creates a new record if there no record at today’s date.
You can otherwise specify a date with '--date'.
Expand All @@ -45,6 +44,7 @@ func (opt *Start) Run(ctx app.Context) app.Error {
ctx.Config().DefaultShouldTotal.Unwrap(func(s klog.ShouldTotal) {
additionalData.ShouldTotal = s
})

spy := PreviousRecordSpy{}
return util.Reconcile(ctx, util.ReconcileOpts{OutputFileArgs: opt.OutputFileArgs, WarnArgs: opt.WarnArgs},
[]reconciling.Creator{
Expand All @@ -63,74 +63,6 @@ func (opt *Start) Run(ctx app.Context) app.Error {
)
}

func (opt *Start) Summary(currentRecord klog.Record, previousRecord klog.Record) (klog.EntrySummary, app.Error) {
// Check for conflicting flags.
if opt.SummaryText != nil && (opt.Resume || opt.ResumeNth != 0) {
return nil, app.NewErrorWithCode(
app.LOGICAL_ERROR,
"Conflicting flags: --summary and --resume cannot be used at the same time",
"",
nil,
)
}
if opt.Resume && opt.ResumeNth != 0 {
return nil, app.NewError(
"Illegal flag combination",
"Cannot combine --resume and --resume-nth",
nil,
)
}

// Return summary flag, if specified.
if opt.SummaryText != nil {
return opt.SummaryText, nil
}

// If --resume was specified: return summary of last entry from current record, if
// it has any entries. Otherwise, return summary of last entry from previous record,
// if exists.
if opt.Resume {
if e, ok := findNthEntry(currentRecord, -1); ok {
return e.Summary(), nil
}
if previousRecord != nil {
if e, ok := findNthEntry(previousRecord, -1); ok {
return e.Summary(), nil
}
}
return nil, nil
}

// If --resume-nth was specified: return summary of nth-entry. In contrast to --resume,
// don’t fall back to previous record, as that would be unintuitive here.
if opt.ResumeNth != 0 {
if e, ok := findNthEntry(currentRecord, opt.ResumeNth); ok {
return e.Summary(), nil
}
return nil, app.NewError(
"No such entry",
"",
nil,
)
}

return nil, nil
}

func findNthEntry(r klog.Record, nr int) (klog.Entry, bool) {
entriesCount := len(r.Entries())
i := func() int {
if nr > 0 {
return nr - 1
}
return entriesCount + nr
}()
if i < 0 || i > entriesCount-1 {
return klog.Entry{}, false
}
return r.Entries()[i], true
}

type PreviousRecordSpy struct {
PreviousRecord klog.Record
}
Expand Down
76 changes: 55 additions & 21 deletions klog/app/cli/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ func TestStartWithSummary(t *testing.T) {
AtDateAndTimeArgs: util.AtDateAndTimeArgs{
AtDateArgs: util.AtDateArgs{Date: klog.Ɀ_Date_(1920, 2, 2)},
},
SummaryText: klog.Ɀ_EntrySummary_("Started something"),
SummaryArgs: util.SummaryArgs{
SummaryText: klog.Ɀ_EntrySummary_("Started something"),
},
}).Run)
require.Nil(t, err)
assert.Equal(t, `
Expand Down Expand Up @@ -267,7 +269,9 @@ func TestStartWithResume(t *testing.T) {
t.Run("No previous entry, no previous record -> Empty entry summary", func(t *testing.T) {
state, err := NewTestingContext()._SetRecords(`1623-12-13
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
Resume: true,
SummaryArgs: util.SummaryArgs{
Resume: true,
},
}).Run)
require.Nil(t, err)
assert.Equal(t, `1623-12-13
Expand All @@ -281,7 +285,9 @@ func TestStartWithResume(t *testing.T) {
14:00 - 15:00 Did something
10m Some activity
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
Resume: true,
SummaryArgs: util.SummaryArgs{
Resume: true,
},
}).Run)
require.Nil(t, err)
assert.Equal(t, `
Expand All @@ -298,7 +304,9 @@ func TestStartWithResume(t *testing.T) {
state, err := NewTestingContext()._SetRecords(`
1623-12-12
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
Resume: true,
SummaryArgs: util.SummaryArgs{
Resume: true,
},
}).Run)
require.Nil(t, err)
assert.Equal(t, `
Expand All @@ -313,7 +321,9 @@ func TestStartWithResume(t *testing.T) {
state, err := NewTestingContext()._SetRecords(`1623-12-13
8:13 - 9:44
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
Resume: true,
SummaryArgs: util.SummaryArgs{
Resume: true,
},
}).Run)
require.Nil(t, err)
assert.Equal(t, `1623-12-13
Expand All @@ -326,7 +336,9 @@ func TestStartWithResume(t *testing.T) {
state, err := NewTestingContext()._SetRecords(`1623-12-13
8:13 - 9:44 Work
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
Resume: true,
SummaryArgs: util.SummaryArgs{
Resume: true,
},
}).Run)
require.Nil(t, err)
assert.Equal(t, `1623-12-13
Expand All @@ -340,7 +352,9 @@ func TestStartWithResume(t *testing.T) {
8:13 - 9:44 Work
9:51 - 11:22 More work
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
Resume: true,
SummaryArgs: util.SummaryArgs{
Resume: true,
},
}).Run)
require.Nil(t, err)
assert.Equal(t, `1623-12-13
Expand All @@ -355,7 +369,9 @@ func TestStartWithResume(t *testing.T) {
8:13 - 9:44
Work
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
Resume: true,
SummaryArgs: util.SummaryArgs{
Resume: true,
},
}).Run)
require.Nil(t, err)
assert.Equal(t, `1623-12-13
Expand All @@ -371,8 +387,10 @@ func TestStartWithResume(t *testing.T) {
8:13 - 9:44
Work
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
Resume: true,
SummaryText: klog.Ɀ_EntrySummary_("Test"),
SummaryArgs: util.SummaryArgs{
Resume: true,
SummaryText: klog.Ɀ_EntrySummary_("Test"),
},
}).Run)
require.Error(t, err)
})
Expand All @@ -382,8 +400,10 @@ func TestStartWithResume(t *testing.T) {
8:13 - 9:44
Work
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
Resume: true,
ResumeNth: 1,
SummaryArgs: util.SummaryArgs{
Resume: true,
ResumeNth: 1,
},
}).Run)
require.Error(t, err)
})
Expand All @@ -397,7 +417,9 @@ func TestStartWithResumeNth(t *testing.T) {
2h Bar
3h Asdf
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
ResumeNth: nth,
SummaryArgs: util.SummaryArgs{
ResumeNth: nth,
},
}).Run)
require.Nil(t, err)
assert.Equal(t, `1623-12-13
Expand All @@ -416,7 +438,9 @@ func TestStartWithResumeNth(t *testing.T) {
2h Bar
3h Asdf
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
ResumeNth: nth,
SummaryArgs: util.SummaryArgs{
ResumeNth: nth,
},
}).Run)
require.Nil(t, err)
assert.Equal(t, `1623-12-13
Expand All @@ -435,7 +459,9 @@ func TestStartWithResumeNth(t *testing.T) {
2h Bar
3h
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
ResumeNth: nth,
SummaryArgs: util.SummaryArgs{
ResumeNth: nth,
},
}).Run)
require.Nil(t, err)
assert.Equal(t, `1623-12-13
Expand All @@ -454,7 +480,9 @@ func TestStartWithResumeNth(t *testing.T) {
2h Bar
3h Asdf
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
ResumeNth: nth,
SummaryArgs: util.SummaryArgs{
ResumeNth: nth,
},
}).Run)
require.Error(t, err)
}
Expand All @@ -468,7 +496,9 @@ func TestStartWithResumeNth(t *testing.T) {
1623-12-13
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
ResumeNth: -1,
SummaryArgs: util.SummaryArgs{
ResumeNth: -1,
},
}).Run)
require.Error(t, err)
})
Expand All @@ -478,8 +508,10 @@ func TestStartWithResumeNth(t *testing.T) {
8:13 - 9:44
Work
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
ResumeNth: 1,
SummaryText: klog.Ɀ_EntrySummary_("Test"),
SummaryArgs: util.SummaryArgs{
ResumeNth: 1,
SummaryText: klog.Ɀ_EntrySummary_("Test"),
},
}).Run)
require.Error(t, err)
})
Expand All @@ -489,8 +521,10 @@ func TestStartWithResumeNth(t *testing.T) {
8:13 - 9:44
Work
`)._SetNow(1623, 12, 13, 12, 49)._Run((&Start{
Resume: true,
ResumeNth: 1,
SummaryArgs: util.SummaryArgs{
Resume: true,
ResumeNth: 1,
},
}).Run)
require.Error(t, err)
})
Expand Down
Loading

0 comments on commit 2f269dc

Please sign in to comment.