diff --git a/README.md b/README.md index d1a309f..875becf 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/z/entry.go b/z/entry.go index 9911493..801240a 100644 --- a/z/entry.go +++ b/z/entry.go @@ -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 = "" diff --git a/z/listCmd.go b/z/listCmd.go index f82c856..ed218d5 100644 --- a/z/listCmd.go +++ b/z/listCmd.go @@ -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() diff --git a/z/rootCmd.go b/z/rootCmd.go index c0148b1..aa2a471 100644 --- a/z/rootCmd.go +++ b/z/rootCmd.go @@ -26,6 +26,7 @@ const( CharErase = " ◀" CharError = " ▲" CharInfo = " ●" + CharMore = " ◆" ) var rootCmd = &cobra.Command{