Merge pull request #38 from schretzi/pr_1

PR1: Add Viper and set some basic for further PRs
This commit is contained in:
マリウス
2025-02-14 00:56:02 +00:00
committed by GitHub
17 changed files with 513 additions and 230 deletions
+334
View File
@@ -0,0 +1,334 @@
## Command structure
| Root | Sub | short-opt | long-opt | Time Option | New |
| ---- | ---------- | --------- | --------------------------- | ----------- | --- |
| zeit | | -h | --help | | |
| | | | --no-colors | | |
| | | | --config | | X |
| | | -d | --debug | | |
| | completion | -h | --help | | |
| | | | --no-descriptions | | |
| | entry | -b | --begin | X | |
| | | | --decimal | | |
| | | -s | --finish | X | |
| | | -h | --help | | |
| | | -n | --notes | | |
| | | -p | --project | | |
| | | -t | --task | | |
| | erase | -h | --help | | |
| | export | -h | --help | | |
| | | | --format | | |
| | | -p | --project | | |
| | | | --range | | X |
| | | | --since | X | |
| | | -t | --task | | |
| | | | --until | X | |
| | finish | -b | --begin | X | |
| | | -s | --finish | X | |
| | | -h | --help | | |
| | | -n | --notes | | |
| | | -p | --project | | |
| | | -t | --task | | |
| | help | -h | --help | | |
| | import | | --format | | |
| | | -h | --help | | |
| | list | | --append-project-id-to-task | | |
| | | | --decimal | | |
| | | -h | --help | | |
| | | | --only-projects-and-tasks | | |
| | | | --only-tasks | | |
| | | -p | --project | | |
| | | | --range | | X |
| | | | --since | X | |
| | | -t | --task | | |
| | | | --total | | |
| | | | --until | X | |
| | project | -c | --color | | |
| | | -h | --help | | |
| | report | -h | --help | | X |
| | | -p | --project | | X |
| | | | --range | | X |
| | | | --since | X | X |
| | | -t | --task | | X |
| | | | --until | X | X |
| | resume | -h | --help | | X |
| | | -b | --begin | X | X |
| | | -s | --finish | X | X |
| | sketchy | -h | --help | | X |
| | stats | | --decimal | | |
| | | -h | --help | | |
| | switch | -h | --help | | X |
| | | -b | --begin | X | X |
| | | -n | --notes | | X |
| | | -p | --project | | X |
| | | -t | --task | | X |
| | switchback | -h | --help | | X |
| | | -b | --begin | X | X |
| | task | -g | --git | | |
| | | -h | --help | | |
| | track | -b | --begin | X | |
| | | -s | --finish | X | |
| | | -f | --force | | |
| | | -n | --notes | | |
| | | -p | --project | | |
| | | -t | --task | | |
| | | -h | --help | | |
| | tracking | -h | --help | | |
| | version | -h | --help | | |
## Changes
### Extension Viper and Cobra
The extension of Cobra with Viper opens up the possibility of persisting time settings in a configuration file. This configuration file is optional, all default settings are chosen so that the behaviour of time does not change if this file does not exist.
By default, this file is searched for in $XDG_CONFIG_HOME/zeit/zeit.yaml (XDG_CONFIG_HOME => $HOME/.config), can also be overwritten with --config.
```
db: /Users/schretzi/OneDrive/Zeit/zeit.db
debug: false
firstWeekDayMonday: true
```
### Linting
I also use GO professionally and as a result I have linter and style checking software running on my system, which report masses of warnings and errors wih the current code. I have cleaned up the code and adapted it according to SolarLint and GO best practices so that my IDE and build tools are clear again and new, real errors are visible.
### Time Parsing
Different places use different parsing of time - track vs. entry. This always leads to errors during entry or some entries have to be unnecessarily long.
I have now combined these processes: I have incorporated dateparse from entryCmd into the helper/parseTime function and then adapted entryCmd so that this function is used via the struct method. This means that all -b and -s parameters now process the time entered in the same way. In my opinion, this should also solve issue #29 in Github.
#### now Library vs. DataParse
Elsewhere, the now library is used to parse time. I did not succeed in deduplicating the two libraries to one, as now does not successfully master most of the test cases. Therefore, I still use DataParse for the inputs and now for the list selection
#### Test Cases
```
go run . track -p "TESTS" -t "Zeit-Test" -b '10:00' -s '11:00'
go run . track -p "TESTS" -t "Zeit-Test" -b '01:00pm' -s '02:00pm'
go run . track -p "TESTS" -t "Zeit-Test" -b '-04:00' -s '-03:00'
go run . track -p "TESTS" -t "Zeit-Test" -b '-02:00' -s '+01:00'
go run . track -p "TESTS" -t "Zeit-Test" -b '2023-09-11 10:00 +0300' -s '2023-09-11 12:00 +0400'
go run . track -p "TESTS" -t "Zeit-Test" -b '2023-09-11 20:00' -s '2023-09-11 21:00'
go run . track -p "TESTS" -t "Zeit-Test" -b '2023-09-11T20:00' -s '2023-09-11T21:00'
go run . track -p "TESTS" -t "Zeit-Test" -b '2023-09-11T20:00:00' -s '2023-09-11T21:00:00'
go run . track -p "TESTS" -t "Zeit-Test" -b '2023-09-11T20:00:00+02:00' -s '2023-09-11T21:00:00+02:00'
```
### Relative Time
Relative time entries are always calculated by time.Now. In the context of tracking new entries this also makes sense, when editing existing entries I would expect the changes to be applied to the existing time, this has now been changed.
```
go run . track -p TESTS -t Rel-Tests -b -01:00 -s +01:00
go run . list
f4297201-c5d9-415b-a7f2-5f39f4fbf19b Rel-Tests on TESTS from 2024-05-18 20:52 +0200 to 2024-05-18 22:52 +0200 (2:00h)
go run . entry f4297201-c5d9-415b-a7f2-5f39f4fbf19b -b -01:00 -s +01:00
go run . list
f4297201-c5d9-415b-a7f2-5f39f4fbf19b Rel-Tests on TESTS from 2024-05-18 19:52 +0200 to 2024-05-18 23:52 +0200 (4:00h)
```
### Round to Minute
My applications do not require billing to the second, minutes are sufficient. At the moment, however, there may be deviations or ambiguities due to rounding. I have added an optional setting which always rounds to the full minute
```
time:
no-seconds: true
```
```
{"begin":"2024-05-18T21:14:06.74637+02:00","finish":"2024-05-18T23:14:06.746393+02:00","project":"TESTS","task":"Rel-Tests","user":"schretzi"}
{"begin":"2024-05-18T21:14:00+02:00","finish":"2024-05-18T23:14:00+02:00","project":"TESTS","task":"Rel-Tests","user":"schretzi"}
```
### Project and Task mandatory with default Project
For my use case, entries without project and task make no sense, most of the time is booked to a project (job). I therefore have the following optional settings:
- Project and task are required, no entry can be created without them
- If no project is passed as a parameter, a default value can be used
```
project:
mandatory: true
default: TESTS
task:
mandatory: true
```
### since/until/range
I always need the same relative time ranges for the list view or the report, setting --since and --until for this is time consuming, so I added the optional --range parameter.If this is set, --since and --until are set to the corresponding values via the now library:
- today
- yesterday
- thisWeek
- lastWeek
- thisMonth
- lastMonth
#### Testcases
```
MONTH=4
YEAR=2024
for i in $(seq 1 30)
do
go run . track -p "TESTS" -t "RangeTests" -b "2024-${MONTH}-${i} 10:00" -s "2024-${MONTH}-${i} 17:00"
done
MONTH=5
YEAR=2024
for i in $(seq 1 19)
do
go run . track -p "TESTS" -t "RangeTests" -b "2024-${MONTH}-${i} 10:00" -s "2024-${MONTH}-${i} 17:00"
done
go run . list --range today
go run . list --range thisWeek
```
### FmtDuration Bug - Open:
fmt.Println(trackDiff)
taskDuration := fmtDuration(trackDiff)
fmt.Println(taskDuration)
1h20m0s
1:19
### New Functions resume / switch / switchback
Some processes that occur in my everyday work have required several steps or entries that can be avoided, so there are three new functions:
- resume: The last task (last entry in the list sorted by start time) is resumed - only the times are provided as parameters, otherwise it would not be the last task
- switch: I always have to interrupt my work due to meetings or operational activities. The switch is used to end the current task at the specified time (-b or now()) and start a new one with the specified parameters
- switchback: After the meeting, I want to resume the previous activity using -b to set the time of the switch
Example procedure: I work on the development of the new functions until the end of the previous day, in the morning I resume work, at 09.00 there is the daily with my team colleagues, then the development is continued:
```
zeit track -p "TESTS" -t "Develop new features" -b "2024-05-18 15:00" -s "2024-05-18 19:00"
▶ tracked Develop new features on TESTS
zeit list
38cdcc16-eb58-4b5b-b564-dbfb979f537c Develop new features on TESTS from 2024-05-18 15:00 +0200 to 2024-05-18 19:00 +0200 (4:00h)
zeit resume -b "2024-05-19 07:40"
▶ began tracking Develop new features on TESTS
zeit list
38cdcc16-eb58-4b5b-b564-dbfb979f537c Develop new features on TESTS from 2024-05-18 15:00 +0200 to 2024-05-18 19:00 +0200 (4:00h)
7461cdf8-efc9-4468-9f7c-8990ab1a62df Develop new features on TESTS from 2024-05-19 07:40 +0200 to 2024-05-19 10:32 +0200 (2:52h) [running]
zeit switch -b 09:00 -t "Daily"
■ finished tracking Develop new features on TESTS for 1:20h
▶ began tracking Daily on TESTS
zeit switchback -b 09:20
■ finished tracking Daily on TESTS for 0:20h
▶ began tracking Develop new features on TESTS
zeit list
38cdcc16-eb58-4b5b-b564-dbfb979f537c Develop new features on TESTS from 2024-05-18 15:00 +0200 to 2024-05-18 19:00 +0200 (4:00h)
7461cdf8-efc9-4468-9f7c-8990ab1a62df Develop new features on TESTS from 2024-05-19 07:40 +0200 to 2024-05-19 09:00 +0200 (1:20h)
421f65b2-291a-47d0-a1b4-4e344ea52731 Daily on TESTS from 2024-05-19 09:00 +0200 to 2024-05-19 09:20 +0200 (0:20h)
81e2ca0f-6de7-4550-ab0b-fc9e3e576544 Develop new features on TESTS from 2024-05-19 09:20 +0200 to 2024-05-19 10:41 +0200 (1:21h) [running]
```
### New Function report
To be able to easily transfer my accumulated times to the time reports of my employer and my private projects, I need a clearer overview than list, but more detailed than stats. Therefore I have created a new function report that totals per day / project / task.
```
 zeit report -h
Reporting summaries on daily, project, task level for a given range
Usage:
zeit report [flags]
Flags:
-h, --help help for report
-p, --project string Project to be listed
--range string shortcut to set since/until for a given range (today, yesterday, thisWeek, lastWeek, thisMonth, lastMonth)
--since string Date/time to start the list from
-t, --task string Task to be listed
--until string Date/time to list until
Global Flags:
--config string config file (default is $XDG_CONFIG_HOME/zeit/zeit.yaml)
-d, --debug Display debugging output in the console. (default: false)
--no-colors Do not use colors in output
```
For a quick overview, there is the option in the configuration file to define a period as the default, in my case the current week
```
report:
default: thisWeek
```
```
 zeit report
Reporting for Timerange: thisWeek / 2024-05-27 - 2024-06-02
2024-05-27 : 3h0m0s
TESTS : 2h0m0s
Testing actual status : 2h0m0s
ZEIT : 1h0m0s
Creating Switch function : 1h0m0s
2024-05-28 : 1h23m0s
ZEIT : 1h23m0s
Creating Report function : 40m0s
Daily : 30m0s
Documentation : 13m0s
```
### New Function sketchy
I work on a Macbook with the Sketchybar as an additional menu bar. In this I would like to display the current status of the time recording. The output of tracking cannot be used 1:1 and I am still considering adding the total hours per day or something similar in the future. Therefore a new function sketchy which has no parameters and calls the sketchbar function to set the label. The path to sketchybar must be set in the configuration file:
```
sketchybar:
path: /opt/homebrew/bin/sketchybar
```
The following paragraph must be added to the sketchbarrc:
```
##### Show actual Zeit tracking
sketchybar --add item zeit e \
--set zeit icon=󱏁 \
script="<PATH TO Zeit>/zeit sketchy" \
update_freq=15
```
This means that the current tracking in the form \<Project>|\<Task> is displayed in the sketch bar to the right of the notch (e): \<Duration>
### Custom Completions for Tasks
After entering -task, \<TAB>\<TAB> displays the list of tasks in the database.
Future topics on this:
- Filter by tasks from projects
- Performance when there are large numbers of entries in the database (it is unclear to me how the performance develops anyway)
## Future Ideas if I find time
- Listing Project (with tasks)
- Listing Tasks
- Archiving Tasks (in sense that autocompletion only shows active tasks)
- UI (report, edit existing tasks)
+18
View File
@@ -10,12 +10,24 @@ require (
github.com/jinzhu/now v1.1.5
github.com/shopspring/decimal v1.4.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/tidwall/buntdb v1.3.2
)
require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/grect v0.1.4 // indirect
@@ -24,5 +36,11 @@ require (
github.com/tidwall/rtred v0.1.2 // indirect
github.com/tidwall/tinyqueue v0.1.1 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+49 -93
View File
@@ -2,112 +2,83 @@ github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhP
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw=
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 h1:ox2F0PSMlrAAiAdknSRMDrAr8mfxPCfSZolH+/qQnyQ=
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08/go.mod h1:pCxVEbcm3AMg7ejXyorUXi6HQCzOIBf7zEDVPtw0/U4=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gookit/color v1.5.0 h1:1Opow3+BWDwqor78DcJkJCIwnkviFi+rrOANki9BUFw=
github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo=
github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ=
github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM=
github.com/gookit/color v1.5.2 h1:uLnfXcaFjlrDnQDT+NCBcfhrXqYTx/rcCa6xn01Y8yI=
github.com/gookit/color v1.5.2/go.mod h1:w8h4bGiHeeBpvQVePTutdbERIUf3oJE5lZ8HM0UgXyg=
github.com/gookit/color v1.5.3 h1:twfIhZs4QLCtimkP7MOxlF3A0U/5cDPseRT9M/+2SCE=
github.com/gookit/color v1.5.3/go.mod h1:NUzwzeehUfl7GIb36pqId+UGmRfQcU/WiiyTTeNjHtE=
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
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=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/tidwall/assert v0.1.0 h1:aWcKyRBUAdLoVebxo95N7+YZVTFF/ASTr7BN4sLP6XI=
github.com/tidwall/assert v0.1.0/go.mod h1:QLYtGyeqse53vuELQheYl9dngGCJQ+mTtlxcktb+Kj8=
github.com/tidwall/btree v1.1.0/go.mod h1:TzIRzen6yHbibdSfK6t8QimqbUnoxUSrZfeW7Uob0q4=
github.com/tidwall/btree v1.3.0 h1:JmIbdbMIYfXJC1SsvbBf3BAU9Re0WQ5lHZ1wvIIY2wg=
github.com/tidwall/btree v1.3.0/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE=
github.com/tidwall/btree v1.3.1 h1:636+tdVDs8Hjcf35Di260W2xCW4KuoXOKyk9QWOvCpA=
github.com/tidwall/btree v1.3.1/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE=
github.com/tidwall/btree v1.4.2 h1:PpkaieETJMUxYNADsjgtNRcERX7mGc/GP2zp/r5FM3g=
github.com/tidwall/btree v1.4.2/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE=
github.com/tidwall/btree v1.5.2 h1:5eA83Gfki799V3d3bJo9sWk+yL2LRoTEah3O/SA6/8w=
github.com/tidwall/btree v1.5.2/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg=
github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tidwall/buntdb v1.2.9 h1:XVz684P7X6HCTrdr385yDZWB1zt/n20ZNG3M1iGyFm4=
github.com/tidwall/buntdb v1.2.9/go.mod h1:IwyGSvvDg6hnKSIhtdZ0AqhCZGH8ukdtCAzaP8fI1X4=
github.com/tidwall/buntdb v1.2.10 h1:U/ebfkmYPBnyiNZIirUiWFcxA/mgzjbKlyPynFsPtyM=
github.com/tidwall/buntdb v1.2.10/go.mod h1:lZZrZUWzlyDJKlLQ6DKAy53LnG7m5kHyrEHvvcDmBpU=
github.com/tidwall/buntdb v1.3.0 h1:gdhWO+/YwoB2qZMeAU9JcWWsHSYU3OvcieYgFRS0zwA=
github.com/tidwall/buntdb v1.3.0/go.mod h1:lZZrZUWzlyDJKlLQ6DKAy53LnG7m5kHyrEHvvcDmBpU=
github.com/tidwall/buntdb v1.3.1 h1:HKoDF01/aBhl9RjYtbaLnvX9/OuenwvQiC3OP1CcL4o=
github.com/tidwall/buntdb v1.3.1/go.mod h1:lZZrZUWzlyDJKlLQ6DKAy53LnG7m5kHyrEHvvcDmBpU=
github.com/tidwall/buntdb v1.3.2 h1:qd+IpdEGs0pZci37G4jF51+fSKlkuUTMXuHhXL1AkKg=
github.com/tidwall/buntdb v1.3.2/go.mod h1:lZZrZUWzlyDJKlLQ6DKAy53LnG7m5kHyrEHvvcDmBpU=
github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.0 h1:6aeJ0bzojgWLa82gDQHcx3S0Lr/O51I9bJ5nv6JFx5w=
github.com/tidwall/gjson v1.14.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw=
github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/grect v0.1.4 h1:dA3oIgNgWdSspFzn1kS4S/RDpZFLrIxAZOdJKjYapOg=
github.com/tidwall/grect v0.1.4/go.mod h1:9FBsaYRaR0Tcy4UwefBX/UDcDcDy9V5jUcxHzv2jd5Q=
github.com/tidwall/lotsa v1.0.2 h1:dNVBH5MErdaQ/xd9s769R31/n2dXavsQ0Yf4TMEHHw8=
github.com/tidwall/lotsa v1.0.2/go.mod h1:X6NiU+4yHA3fE3Puvpnn1XMDrFZrE9JO2/w+UMuqgR8=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
@@ -115,37 +86,22 @@ github.com/tidwall/rtred v0.1.2 h1:exmoQtOLvDoO8ud++6LwVsAMTu0KPzLTUrMln8u1yu8=
github.com/tidwall/rtred v0.1.2/go.mod h1:hd69WNXQ5RP9vHd7dqekAz+RIdtfBogmglkZSRxCHFQ=
github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE=
github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b h1:2n253B2r0pYSmEV+UNCQoPfU/FiaizQEK5Gu4Bq4JE8=
golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220731174439-a90be440212d h1:Sv5ogFZatcgIMMtBSTTAgMYsicp25MXBubjXNDKwm80=
golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 h1:v6hYoSR9T5oet+pMXwUWkbiVqx/63mlHjefrHmxwfeY=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+7
View File
@@ -0,0 +1,7 @@
package z
const (
FlagNoColors string = "no-colors"
FlagDebug string = "debug"
)
+3 -3
View File
@@ -4,12 +4,12 @@ import (
"encoding/json"
"errors"
"log"
"os"
"sort"
"strings"
"github.com/google/uuid"
"github.com/tidwall/buntdb"
"github.com/spf13/viper"
)
type Database struct {
@@ -17,8 +17,8 @@ type Database struct {
}
func InitDatabase() (*Database, error) {
dbfile, ok := os.LookupEnv("ZEIT_DB")
if ok == false || dbfile == "" {
dbfile := viper.GetString("db")
if dbfile == "" {
return nil, errors.New("please `export ZEIT_DB` to the location the zeit database should be stored at")
}
+57 -64
View File
@@ -1,83 +1,76 @@
package z
import (
"fmt"
"os"
"strings"
"fmt"
"os"
"strings"
"github.com/araddon/dateparse"
"github.com/spf13/cobra"
"github.com/araddon/dateparse"
"github.com/spf13/cobra"
)
var entryCmd = &cobra.Command{
Use: "entry ([flags]) [id]",
Short: "Display or update activity",
Long: "Display or update tracked activity.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
user := GetCurrentUser()
id := args[0]
Use: "entry ([flags]) [id]",
Short: "Display or update activity",
Long: "Display or update tracked activity.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
user := GetCurrentUser()
id := args[0]
entry, err := database.GetEntry(user, id)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
entry, err := database.GetEntry(user, id)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
if begin != "" || finish != "" || project != "" || notes != "" || task != "" {
if begin != "" {
entry.Begin, err = dateparse.ParseAny(begin)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
if begin != "" || finish != "" || project != "" || notes != "" || task != "" {
if begin != "" {
entry.Begin, err = dateparse.ParseAny(begin)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
if finish != "" {
entry.Finish, err = dateparse.ParseAny(finish)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
if finish != "" {
entry.Finish, err = dateparse.ParseAny(finish)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
if project != "" {
entry.Project = project
}
if project != "" {
entry.Project = project
}
if task != "" {
entry.Task = task
}
if task != "" {
entry.Task = task
}
if notes != "" {
entry.Notes = strings.Replace(notes, "\\n", "\n", -1)
}
if notes != "" {
entry.Notes = strings.Replace(notes, "\\n", "\n", -1)
}
_, err = database.UpdateEntry(user, entry)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
_, err = database.UpdateEntry(user, entry)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
fmt.Printf("%s %s\n", CharInfo, entry.GetOutput(true))
return
},
fmt.Printf("%s %s\n", CharInfo, entry.GetOutput(true))
return
},
}
func init() {
rootCmd.AddCommand(entryCmd)
entryCmd.Flags().StringVarP(&begin, "begin", "b", "", "Update date/time the activity began at")
entryCmd.Flags().StringVarP(&finish, "finish", "s", "", "Update date/time the activity finished at")
entryCmd.Flags().StringVarP(&project, "project", "p", "", "Update activity project")
entryCmd.Flags().StringVarP(&notes, "notes", "n", "", "Update activity notes")
entryCmd.Flags().StringVarP(&task, "task", "t", "", "Update activity task")
entryCmd.Flags().BoolVar(&fractional, "decimal", false, "Show fractional hours in decimal format instead of minutes")
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
rootCmd.AddCommand(entryCmd)
entryCmd.Flags().StringVarP(&begin, "begin", "b", "", "Update date/time the activity began at")
entryCmd.Flags().StringVarP(&finish, "finish", "s", "", "Update date/time the activity finished at")
entryCmd.Flags().StringVarP(&project, "project", "p", "", "Update activity project")
entryCmd.Flags().StringVarP(&notes, "notes", "n", "", "Update activity notes")
entryCmd.Flags().StringVarP(&task, "task", "t", "", "Update activity task")
entryCmd.Flags().BoolVar(&fractional, "decimal", false, "Show fractional hours in decimal format instead of minutes")
}
-7
View File
@@ -29,11 +29,4 @@ var eraseCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(eraseCmd)
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
-7
View File
@@ -102,11 +102,4 @@ func init() {
exportCmd.Flags().StringVar(&until, "until", "", "Date/time to export until")
exportCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be exported")
exportCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be exported")
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
-7
View File
@@ -104,11 +104,4 @@ func init() {
finishCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be assigned")
finishCmd.Flags().StringVarP(&notes, "notes", "n", "", "Activity notes")
finishCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be assigned")
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
-7
View File
@@ -108,11 +108,4 @@ var importCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(importCmd)
importCmd.Flags().StringVar(&format, "format", "zeit", "Format to import, possible values: zeit, tyme")
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
-7
View File
@@ -115,11 +115,4 @@ func init() {
listCmd.Flags().BoolVar(&listOnlyProjectsAndTasks, "only-projects-and-tasks", false, "Only list projects and their tasks, no entries")
listCmd.Flags().BoolVar(&listOnlyTasks, "only-tasks", false, "Only list tasks, no projects nor entries")
listCmd.Flags().BoolVar(&appendProjectIDToTask, "append-project-id-to-task", false, "Append project ID to tasks in the list")
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
-7
View File
@@ -45,11 +45,4 @@ var projectCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(projectCmd)
projectCmd.Flags().StringVarP(&projectColor, "color", "c", "", "Set the color of the project (hex code, e.g. #121212)")
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
+45 -1
View File
@@ -3,6 +3,7 @@ package z
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/gookit/color"
"os"
)
@@ -22,6 +23,8 @@ var format string
var force bool
var noColors bool
var debug bool
var cfgFile string
const(
CharTrack = " ▶"
@@ -48,11 +51,52 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().BoolVar(&noColors, "no-colors", false, "Do not use colors in output")
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $XDG_CONFIG_HOME/zeit.[yaml|toml")
rootCmd.PersistentFlags().BoolVar(&noColors, FlagNoColors, false, "Do not use colors in output")
viper.BindPFlag(FlagNoColors, rootCmd.PersistentFlags().Lookup(FlagNoColors))
rootCmd.PersistentFlags().BoolVarP(&debug, FlagDebug, "d", false, "Display debugging output in the console. (default: false)")
viper.BindPFlag(FlagDebug, rootCmd.PersistentFlags().Lookup(FlagDebug))
}
func initConfig() {
if noColors == true {
color.Disable()
}
viper.SetEnvPrefix("zeit")
viper.BindEnv("db")
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := os.UserHomeDir()
cobra.CheckErr(err)
viper.AddConfigPath("$XDG_CONFIG_HOME")
viper.AddConfigPath("$XDG_CONFIG_HOME/zeit")
viper.AddConfigPath(home + "/.config")
viper.AddConfigPath(home + "/.config/zeit")
viper.SetConfigName("zeit")
}
if err := viper.ReadInConfig(); err != nil {
// Set default values for parameters
viper.Set("debug", false)
}
if viper.GetBool("debug") {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
fmt.Fprintln(os.Stderr, "Using Database file:", viper.GetString("db"))
}
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
-6
View File
@@ -52,10 +52,4 @@ var statsCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(statsCmd)
statsCmd.Flags().BoolVar(&fractional, "decimal", false, "Show fractional hours in decimal format instead of minutes")
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
-7
View File
@@ -45,11 +45,4 @@ var taskCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(taskCmd)
taskCmd.Flags().StringVarP(&taskGitRepository, "git", "g", "-", "Set the task's Git repository to enable commit message importing into activity notes.\nSet to an empty string '' to remove a previously set repository and disable git log imports.")
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
-7
View File
@@ -55,11 +55,4 @@ func init() {
trackCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be assigned")
trackCmd.Flags().StringVarP(&notes, "notes", "n", "", "Activity notes")
trackCmd.Flags().BoolVarP(&force, "force", "f", false, "Force begin tracking of a new task \neven though another one is still running \n(ONLY IF YOU KNOW WHAT YOU'RE DOING!)")
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
-7
View File
@@ -37,11 +37,4 @@ var trackingCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(trackingCmd)
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}