Implemented projects/tasks structure listing; this implements #1 partially
This commit is contained in:
parent
59c05b1ac9
commit
2d7dbddf5c
4 changed files with 69 additions and 3 deletions
33
README.md
33
README.md
|
@ -126,10 +126,43 @@ zeit finish --begin 16:00
|
||||||
|
|
||||||
### List tracked activity
|
### List tracked activity
|
||||||
|
|
||||||
|
```sh
|
||||||
|
zeit list --help
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Examples:
|
||||||
|
|
||||||
|
List all tracked activities:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
zeit list
|
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
|
### Display/update activity
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gookit/color"
|
"github.com/gookit/color"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Entry struct {
|
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)
|
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) {
|
func (entry *Entry) GetOutputForFinish() (string) {
|
||||||
var outputSuffix string = ""
|
var outputSuffix string = ""
|
||||||
|
|
||||||
|
|
32
z/listCmd.go
32
z/listCmd.go
|
@ -9,6 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var listTotalTime bool
|
var listTotalTime bool
|
||||||
|
var listOnlyProjectsAndTasks bool
|
||||||
|
|
||||||
var listCmd = &cobra.Command{
|
var listCmd = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list",
|
||||||
|
@ -49,11 +50,35 @@ var listCmd = &cobra.Command{
|
||||||
os.Exit(1)
|
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);
|
totalHours := decimal.NewFromInt(0);
|
||||||
for _, entry := range filteredEntries {
|
for _, entry := range filteredEntries {
|
||||||
duration := entry.Finish.Sub(entry.Begin)
|
totalHours = totalHours.Add(entry.GetDuration())
|
||||||
durationDec := decimal.NewFromFloat(duration.Hours())
|
|
||||||
totalHours = totalHours.Add(durationDec)
|
|
||||||
fmt.Printf("%s\n", entry.GetOutput(false))
|
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(&project, "project", "p", "", "Project to be listed")
|
||||||
listCmd.Flags().StringVarP(&task, "task", "t", "", "Task 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(&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
|
var err error
|
||||||
database, err = InitDatabase()
|
database, err = InitDatabase()
|
||||||
|
|
|
@ -26,6 +26,7 @@ const(
|
||||||
CharErase = " ◀"
|
CharErase = " ◀"
|
||||||
CharError = " ▲"
|
CharError = " ▲"
|
||||||
CharInfo = " ●"
|
CharInfo = " ●"
|
||||||
|
CharMore = " ◆"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
|
|
Loading…
Reference in a new issue