-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix pass-through of input arguments * Naming * Error on negative index * Setup `track` command * Migrate from `ioutil` to `io` * Improve help text * Make reconciler predicate-based * Return resulting record and customise “not found” error * Unify date options and add shortcuts * Naming * Add `start` command * Add comments, naming * Make reconciler object-oriented * Restructure code * Add `stop` command * Improve error messages * Make time configurable * Help text * Add command for adding new record * Keep templates hidden * Add should total * Unhide manipulation commands * Make written file contents testable * Fix position when inserting block
- Loading branch information
Showing
41 changed files
with
950 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cli | ||
|
||
import ( | ||
. "klog" | ||
"klog/app" | ||
"klog/app/cli/lib" | ||
"klog/parser" | ||
"klog/parser/parsing" | ||
) | ||
|
||
type Create struct { | ||
Template string `name:"template" hidden help:"The name of the template to instantiate"` | ||
ShouldTotal Duration `name:"should" help:"A should total property"` | ||
lib.AtDateArgs | ||
lib.OutputFileArgs | ||
} | ||
|
||
func (opt *Create) Run(ctx app.Context) error { | ||
date := opt.AtDate(ctx.Now()) | ||
lines, err := func() ([]parsing.Text, error) { | ||
if opt.Template != "" { | ||
return ctx.InstantiateTemplate(opt.Template) | ||
} | ||
headline := opt.AtDate(ctx.Now()).ToString() | ||
if opt.ShouldTotal != nil { | ||
headline += " (" + opt.ShouldTotal.ToString() + "!)" | ||
} | ||
return []parsing.Text{ | ||
{headline, 0}, | ||
}, nil | ||
}() | ||
if err != nil { | ||
return err | ||
} | ||
return reconcile( | ||
opt.OutputFileArgs, | ||
ctx, | ||
func(pr *parser.ParseResult) (*parser.Reconciler, error) { | ||
return parser.NewBlockReconciler(pr, func(r1 Record, r2 Record) bool { | ||
return date.IsAfterOrEqual(r1.Date()) && r2.Date().IsAfterOrEqual(date) | ||
}) | ||
}, | ||
func(r *parser.Reconciler) (Record, string, error) { | ||
return r.AddBlock(lines) | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"klog" | ||
"klog/app/cli/lib" | ||
"testing" | ||
) | ||
|
||
func TestCreate(t *testing.T) { | ||
state, err := NewTestingContext()._SetRecords(` | ||
1920-02-01 | ||
4h33m | ||
1920-02-02 | ||
9:00-12:00 | ||
`)._SetNow(1920, 2, 3, 15, 24)._Run((&Create{}).Run) | ||
require.Nil(t, err) | ||
assert.Equal(t, ` | ||
1920-02-01 | ||
4h33m | ||
1920-02-02 | ||
9:00-12:00 | ||
1920-02-03 | ||
`, state.writtenFileContents) | ||
} | ||
|
||
func TestCreateWithValues(t *testing.T) { | ||
state, err := NewTestingContext()._SetRecords(` | ||
1975-12-31 | ||
1h | ||
2h | ||
1976-01-01 | ||
1h | ||
`)._Run((&Create{ | ||
AtDateArgs: lib.AtDateArgs{Date: klog.Ɀ_Date_(1976, 1, 2)}, | ||
ShouldTotal: klog.NewDuration(5, 55), | ||
}).Run) | ||
require.Nil(t, err) | ||
assert.Equal(t, ` | ||
1975-12-31 | ||
1h | ||
2h | ||
1976-01-01 | ||
1h | ||
1976-01-02 (5h55m!) | ||
`, state.writtenFileContents) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.