Implemented projects/tasks structure listing; this implements #1 partially

This commit is contained in:
マリウス 2020-10-21 00:04:51 +01:00
parent 59c05b1ac9
commit 2d7dbddf5c
No known key found for this signature in database
GPG key ID: C228EF0A530AF06F
4 changed files with 69 additions and 3 deletions

View file

@ -126,10 +126,43 @@ zeit finish --begin 16:00
### List tracked activity
```sh
zeit list --help
```
#### Examples:
List all tracked activities:
```sh
zeit list
```
List all tracked activities since a specific date/time:
```sh
zeit list --since "2020-10-14T00:00:01+01:00"
```
List all tracked activities and add the total hours:
```sh
zeit list --total
```
List only projects and tasks (relational):
```sh
zeit list --only-projects-and-tasks
```
List only projects and tasks (relational) that were tracked since a specific
date/time:
```sh
zeit list --only-projects-and-tasks --since "2020-10-14T00:00:01+01:00"
```
### Display/update activity

View file

@ -6,6 +6,7 @@ import (
"time"
"fmt"
"github.com/gookit/color"
"github.com/shopspring/decimal"
)
type Entry struct {
@ -128,6 +129,11 @@ func (entry *Entry) GetOutputForTrack(isRunning bool, wasRunning bool) (string)
return fmt.Sprintf("%s %s task%s\n", CharTrack, outputPrefix, outputSuffix)
}
func (entry *Entry) GetDuration() (decimal.Decimal) {
duration := entry.Finish.Sub(entry.Begin)
return decimal.NewFromFloat(duration.Hours())
}
func (entry *Entry) GetOutputForFinish() (string) {
var outputSuffix string = ""

View file

@ -9,6 +9,7 @@ import (
)
var listTotalTime bool
var listOnlyProjectsAndTasks bool
var listCmd = &cobra.Command{
Use: "list",
@ -49,11 +50,35 @@ var listCmd = &cobra.Command{
os.Exit(1)
}
if listOnlyProjectsAndTasks == true {
var projectsAndTasks = make(map[string]map[string]bool)
for _, filteredEntry := range filteredEntries {
taskMap, ok := projectsAndTasks[filteredEntry.Project]
if !ok {
taskMap = make(map[string]bool)
projectsAndTasks[filteredEntry.Project] = taskMap
}
taskMap[filteredEntry.Task] = true
projectsAndTasks[filteredEntry.Project] = taskMap
}
for project, _ := range projectsAndTasks {
fmt.Printf("%s %s\n", CharMore, project)
for task, _ := range projectsAndTasks[project] {
fmt.Printf("%*s└── %s\n", 1, " ", task)
}
}
return
}
totalHours := decimal.NewFromInt(0);
for _, entry := range filteredEntries {
duration := entry.Finish.Sub(entry.Begin)
durationDec := decimal.NewFromFloat(duration.Hours())
totalHours = totalHours.Add(durationDec)
totalHours = totalHours.Add(entry.GetDuration())
fmt.Printf("%s\n", entry.GetOutput(false))
}
@ -71,6 +96,7 @@ func init() {
listCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be listed")
listCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be listed")
listCmd.Flags().BoolVar(&listTotalTime, "total", false, "Show total time of hours for listed activities")
listCmd.Flags().BoolVar(&listOnlyProjectsAndTasks, "only-projects-and-tasks", false, "Only list projects and their tasks, no entries")
var err error
database, err = InitDatabase()

View file

@ -26,6 +26,7 @@ const(
CharErase = " ◀"
CharError = " ▲"
CharInfo = " ●"
CharMore = " ◆"
)
var rootCmd = &cobra.Command{