Consolidated list/export further, extended list command
This commit is contained in:
parent
86662a5a37
commit
fda944ab17
3 changed files with 44 additions and 13 deletions
21
z/export.go
21
z/export.go
|
@ -8,9 +8,6 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var exportSince string
|
||||
var exportUntil string
|
||||
|
||||
func exportZeitJson(user string, entries []Entry) (string, error) {
|
||||
stringified, err := json.Marshal(entries)
|
||||
if err != nil {
|
||||
|
@ -47,19 +44,19 @@ var exportCmd = &cobra.Command{
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
var since time.Time
|
||||
var until time.Time
|
||||
var sinceTime time.Time
|
||||
var untilTime time.Time
|
||||
|
||||
if exportSince != "" {
|
||||
since, err = time.Parse(time.RFC3339, exportSince)
|
||||
if since != "" {
|
||||
sinceTime, err = time.Parse(time.RFC3339, since)
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
if exportUntil != "" {
|
||||
until, err = time.Parse(time.RFC3339, exportUntil)
|
||||
if until != "" {
|
||||
untilTime, err = time.Parse(time.RFC3339, until)
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
|
@ -67,7 +64,7 @@ var exportCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
var filteredEntries []Entry
|
||||
filteredEntries, err = GetFilteredEntries(entries, project, task, since, until)
|
||||
filteredEntries, err = GetFilteredEntries(entries, project, task, sinceTime, untilTime)
|
||||
if err != nil {
|
||||
fmt.Printf("%s %+v\n", CharError, err)
|
||||
os.Exit(1)
|
||||
|
@ -100,8 +97,8 @@ var exportCmd = &cobra.Command{
|
|||
func init() {
|
||||
rootCmd.AddCommand(exportCmd)
|
||||
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(&exportUntil, "until", "", "Date/time to export until")
|
||||
exportCmd.Flags().StringVar(&since, "since", "", "Date/time to start the export from")
|
||||
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")
|
||||
|
||||
|
|
33
z/list.go
33
z/list.go
|
@ -3,6 +3,7 @@ package z
|
|||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
"time"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -19,7 +20,33 @@ var listCmd = &cobra.Command{
|
|||
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())
|
||||
}
|
||||
|
||||
|
@ -29,6 +56,10 @@ var listCmd = &cobra.Command{
|
|||
|
||||
func init() {
|
||||
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
|
||||
database, err = InitDatabase()
|
||||
|
|
|
@ -14,6 +14,9 @@ var project string
|
|||
var task string
|
||||
var notes string
|
||||
|
||||
var since string
|
||||
var until string
|
||||
|
||||
var format string
|
||||
var force bool
|
||||
|
||||
|
|
Loading…
Reference in a new issue