Consolidated list/export further, extended list command

This commit is contained in:
マリウス 2020-10-17 20:06:25 +01:00
parent 86662a5a37
commit fda944ab17
No known key found for this signature in database
GPG key ID: C228EF0A530AF06F
3 changed files with 44 additions and 13 deletions

View file

@ -8,9 +8,6 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var exportSince string
var exportUntil string
func exportZeitJson(user string, entries []Entry) (string, error) { func exportZeitJson(user string, entries []Entry) (string, error) {
stringified, err := json.Marshal(entries) stringified, err := json.Marshal(entries)
if err != nil { if err != nil {
@ -47,19 +44,19 @@ var exportCmd = &cobra.Command{
os.Exit(1) os.Exit(1)
} }
var since time.Time var sinceTime time.Time
var until time.Time var untilTime time.Time
if exportSince != "" { if since != "" {
since, err = time.Parse(time.RFC3339, exportSince) sinceTime, err = time.Parse(time.RFC3339, since)
if err != nil { if err != nil {
fmt.Printf("%s %+v\n", CharError, err) fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1) os.Exit(1)
} }
} }
if exportUntil != "" { if until != "" {
until, err = time.Parse(time.RFC3339, exportUntil) untilTime, err = time.Parse(time.RFC3339, until)
if err != nil { if err != nil {
fmt.Printf("%s %+v\n", CharError, err) fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1) os.Exit(1)
@ -67,7 +64,7 @@ var exportCmd = &cobra.Command{
} }
var filteredEntries []Entry var filteredEntries []Entry
filteredEntries, err = GetFilteredEntries(entries, project, task, since, until) filteredEntries, err = GetFilteredEntries(entries, project, task, sinceTime, untilTime)
if err != nil { if err != nil {
fmt.Printf("%s %+v\n", CharError, err) fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1) os.Exit(1)
@ -100,8 +97,8 @@ var exportCmd = &cobra.Command{
func init() { func init() {
rootCmd.AddCommand(exportCmd) rootCmd.AddCommand(exportCmd)
exportCmd.Flags().StringVar(&format, "format", "", "Format to export, possible values: zeit, tyme") exportCmd.Flags().StringVar(&format, "format", "", "Format to export, possible values: zeit, tyme")
exportCmd.Flags().StringVar(&exportSince, "since", "", "Date/time to start the export from") exportCmd.Flags().StringVar(&since, "since", "", "Date/time to start the export from")
exportCmd.Flags().StringVar(&exportUntil, "until", "", "Date/time to export until") exportCmd.Flags().StringVar(&until, "until", "", "Date/time to export until")
exportCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be exported") exportCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be exported")
exportCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be exported") exportCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be exported")

View file

@ -3,6 +3,7 @@ package z
import ( import (
"os" "os"
"fmt" "fmt"
"time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -19,7 +20,33 @@ var listCmd = &cobra.Command{
os.Exit(1) os.Exit(1)
} }
for _, entry := range entries { var sinceTime time.Time
var untilTime time.Time
if since != "" {
sinceTime, err = time.Parse(time.RFC3339, since)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
if until != "" {
untilTime, err = time.Parse(time.RFC3339, until)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}
var filteredEntries []Entry
filteredEntries, err = GetFilteredEntries(entries, project, task, sinceTime, untilTime)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
for _, entry := range filteredEntries {
fmt.Printf("%s\n", entry.GetOutput()) fmt.Printf("%s\n", entry.GetOutput())
} }
@ -29,6 +56,10 @@ var listCmd = &cobra.Command{
func init() { func init() {
rootCmd.AddCommand(listCmd) rootCmd.AddCommand(listCmd)
listCmd.Flags().StringVar(&since, "since", "", "Date/time to start the list from")
listCmd.Flags().StringVar(&until, "until", "", "Date/time to list until")
listCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be listed")
listCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be listed")
var err error var err error
database, err = InitDatabase() database, err = InitDatabase()

View file

@ -14,6 +14,9 @@ var project string
var task string var task string
var notes string var notes string
var since string
var until string
var format string var format string
var force bool var force bool