@@ -36,67 +36,66 @@ const (
36
36
// entries
37
37
type TimeEntryOutputOptions struct {
38
38
ShowTasks bool
39
+ ShowClients bool
39
40
ShowTotalDuration bool
40
41
TimeFormat string
41
42
}
42
43
43
- // WithTimeFormat sets the date-time output format
44
- func WithTimeFormat (format string ) TimeEntryOutputOpt {
45
- return func (teo * TimeEntryOutputOptions ) error {
46
- teo .TimeFormat = format
47
- return nil
44
+ // NewTimeEntryOutputOptions creates a default TimeEntryOutputOptions
45
+ func NewTimeEntryOutputOptions () TimeEntryOutputOptions {
46
+ return TimeEntryOutputOptions {
47
+ TimeFormat : TimeFormatSimple ,
48
+ ShowTasks : false ,
49
+ ShowClients : false ,
50
+ ShowTotalDuration : false ,
48
51
}
49
52
}
50
53
54
+ // WithTimeFormat sets the date-time output format
55
+ func (teo TimeEntryOutputOptions ) WithTimeFormat (
56
+ format string ) TimeEntryOutputOptions {
57
+ teo .TimeFormat = format
58
+ return teo
59
+
60
+ }
61
+
51
62
// WithShowTasks shows a new column with the task of the time entry
52
- func WithShowTasks () TimeEntryOutputOpt {
53
- return func (teoo * TimeEntryOutputOptions ) error {
54
- teoo .ShowTasks = true
55
- return nil
56
- }
63
+ func (teo TimeEntryOutputOptions ) WithShowTasks () TimeEntryOutputOptions {
64
+ teo .ShowTasks = true
65
+ return teo
66
+ }
67
+
68
+ // WithShowCliens shows a new column with the client of the time entry
69
+ func (teo TimeEntryOutputOptions ) WithShowClients () TimeEntryOutputOptions {
70
+ teo .ShowClients = true
71
+ return teo
57
72
}
58
73
59
74
// WithTotalDuration shows a footer with the sum of the durations of the time
60
75
// entries
61
- func WithTotalDuration () TimeEntryOutputOpt {
62
- return func (teoo * TimeEntryOutputOptions ) error {
63
- teoo .ShowTotalDuration = true
64
- return nil
65
- }
76
+ func (teo TimeEntryOutputOptions ) WithTotalDuration () TimeEntryOutputOptions {
77
+ teo .ShowTotalDuration = true
78
+ return teo
66
79
}
67
80
68
- // TimeEntryOutputOpt allows the setting of TimeEntryOutputOptions values
69
- type TimeEntryOutputOpt func (* TimeEntryOutputOptions ) error
70
-
71
81
// TimeEntriesPrint will print more details
72
- func TimeEntriesPrint (opts ... TimeEntryOutputOpt ) func ([]dto.TimeEntry , io.Writer ) error {
73
- options := & TimeEntryOutputOptions {
74
- TimeFormat : TimeFormatSimple ,
75
- ShowTasks : false ,
76
- ShowTotalDuration : false ,
77
- }
78
-
79
- for _ , o := range opts {
80
- err := o (options )
81
- if err != nil {
82
- return func (te []dto.TimeEntry , w io.Writer ) error { return err }
83
- }
84
- }
85
-
82
+ func TimeEntriesPrint (
83
+ options TimeEntryOutputOptions ) func ([]dto.TimeEntry , io.Writer ) error {
86
84
return func (timeEntries []dto.TimeEntry , w io.Writer ) error {
87
85
tw := tablewriter .NewWriter (w )
88
- taskColumn := 6
89
86
projectColumn := 4
90
- header := []string {"ID" , "Start" , "End" , "Dur" ,
91
- "Project" , "Description" , "Tags" }
87
+ header := []string {"ID" , "Start" , "End" , "Dur" , "Project" }
88
+
92
89
if options .ShowTasks {
93
- header = append (
94
- header [:taskColumn ],
95
- header [taskColumn - 1 :]... ,
96
- )
97
- header [taskColumn ] = "Task"
90
+ header = append (header , "Client" )
98
91
}
99
92
93
+ if options .ShowTasks {
94
+ header = append (header , "Task" )
95
+ }
96
+
97
+ header = append (header , "Description" , "Tags" )
98
+
100
99
tw .SetHeader (header )
101
100
tw .SetRowLine (true )
102
101
if width , _ , err := term .GetSize (int (os .Stdout .Fd ())); err == nil {
@@ -124,18 +123,31 @@ func TimeEntriesPrint(opts ...TimeEntryOutputOpt) func([]dto.TimeEntry, io.Write
124
123
end .In (time .Local ).Format (options .TimeFormat ),
125
124
durationToString (end .Sub (t .TimeInterval .Start )),
126
125
projectName ,
127
- t .Description ,
128
- strings .Join (tagsToStringSlice (t .Tags ), "\n " ),
126
+ }
127
+
128
+ if options .ShowClients {
129
+ client := ""
130
+ if t .Project .ClientName != "" {
131
+ colors [len (line )] = colors [projectColumn ]
132
+ client = t .Project .ClientName
133
+ }
134
+ line = append (line , client )
129
135
}
130
136
131
137
if options .ShowTasks {
132
- line = append (line [:taskColumn ], line [taskColumn - 1 :]... )
133
- line [taskColumn ] = ""
138
+ task := ""
134
139
if t .Task != nil {
135
- line [ taskColumn ] = fmt .Sprintf ("%s (%s)" , t .Task .Name , t .Task .ID )
140
+ task = fmt .Sprintf ("%s (%s)" , t .Task .Name , t .Task .ID )
136
141
}
142
+ line = append (line , task )
137
143
}
138
144
145
+ line = append (
146
+ line ,
147
+ t .Description ,
148
+ strings .Join (tagsToStringSlice (t .Tags ), "\n " ),
149
+ )
150
+
139
151
tw .Rich (line , colors )
140
152
}
141
153
0 commit comments