@@ -11,22 +11,27 @@ import (
1111)
1212
1313// Adds programs into the database, and sends communication to service to being tracking them
14- func (s * CLIService ) AddPrograms (ctx context.Context , args []string ) error {
15- var addedPrograms []string
14+ func (s * CLIService ) AddPrograms (ctx context.Context , args []string , category string ) error {
15+ categoryNull := sql.NullString {
16+ String : category ,
17+ Valid : category != "" ,
18+ }
19+
1620 for _ , program := range args {
17- err := s .PrRepo .AddProgram (ctx , strings .ToLower (program ))
21+ err := s .PrRepo .AddProgram (ctx , database.AddProgramParams {
22+ Name : strings .ToLower (program ),
23+ Category : categoryNull ,
24+ })
1825 if err != nil {
1926 return fmt .Errorf ("error adding program %s: %w" , program , err )
2027 }
21- addedPrograms = append (addedPrograms , program )
2228 }
2329
2430 err := s .ServiceCmd .WriteToService ()
2531 if err != nil {
2632 return fmt .Errorf ("programs added but failed to notify service: %w" , err )
2733 }
2834
29- fmt .Printf ("Added %d program(s) to track\n " , len (addedPrograms ))
3035 return nil
3136}
3237
@@ -43,25 +48,21 @@ func (s *CLIService) RemovePrograms(ctx context.Context, args []string, all bool
4348 return fmt .Errorf ("error alerting service of program removal: %w" , err )
4449 }
4550
46- fmt .Println ("All programs removed from tracking" )
4751 return nil
4852 }
4953
50- var removedPrograms []string
5154 for _ , program := range args {
5255 err := s .PrRepo .RemoveProgram (ctx , strings .ToLower (program ))
5356 if err != nil {
5457 return fmt .Errorf ("error removing program %s: %w" , program , err )
5558 }
56- removedPrograms = append (removedPrograms , program )
5759 }
5860
5961 err := s .ServiceCmd .WriteToService ()
6062 if err != nil {
6163 return fmt .Errorf ("programs removed but failed to notify service: %w" , err )
6264 }
6365
64- fmt .Printf ("Removed %d program(s) from tracking\n " , len (removedPrograms ))
6566 return nil
6667}
6768
@@ -73,11 +74,9 @@ func (s *CLIService) GetList(ctx context.Context) error {
7374 }
7475
7576 if len (programs ) == 0 {
76- fmt .Println ("No programs are currently being tracked" )
7777 return nil
7878 }
7979
80- fmt .Println ("Programs currently being tracked:" )
8180 for _ , program := range programs {
8281 fmt .Printf (" • %s\n " , program )
8382 }
@@ -93,7 +92,6 @@ func (s *CLIService) GetAllInfo(ctx context.Context) error {
9392 }
9493
9594 if len (programs ) == 0 {
96- fmt .Println ("No programs are currently being tracked" )
9795 return nil
9896 }
9997
@@ -126,7 +124,7 @@ func (s *CLIService) GetInfo(ctx context.Context, args []string) error {
126124 lastSession , err := s .HsRepo .GetLastSessionForProgram (ctx , program .Name )
127125 if err != nil {
128126 if err == sql .ErrNoRows {
129- fmt .Printf ("Statistics for %s: \n " , program .Name )
127+ fmt .Printf (" • Category: %s " , program .Category . String )
130128 s .formatDuration (" • Current Lifetime: " , duration )
131129 fmt .Printf (" • Total sessions to date: 0\n " )
132130 fmt .Printf (" • Last Session: No sessions recorded yet\n " )
@@ -141,7 +139,7 @@ func (s *CLIService) GetInfo(ctx context.Context, args []string) error {
141139 return fmt .Errorf ("error getting history count for %s: %w" , program .Name , err )
142140 }
143141
144- fmt .Printf ("Statistics for %s: \n " , program .Name )
142+ fmt .Printf (" • Category: %s " , program .Category . String )
145143 s .formatDuration (" • Current Lifetime: " , duration )
146144 fmt .Printf (" • Total sessions to date: %d\n " , sessionCount )
147145
@@ -184,16 +182,9 @@ func (s *CLIService) GetSessionHistory(ctx context.Context, args []string, date,
184182 }
185183
186184 if len (history ) == 0 {
187- fmt .Println ("No session history present" )
188185 return nil
189186 }
190187
191- if programName != "" {
192- fmt .Printf ("Session history for %s: \n " , programName )
193- } else {
194- fmt .Println ("Session history: " )
195- }
196-
197188 for _ , session := range history {
198189 printSession (session )
199190 }
@@ -208,7 +199,6 @@ func (s *CLIService) ResetStats(ctx context.Context, args []string, all bool) er
208199 if err != nil {
209200 return err
210201 }
211- fmt .Println ("All session records reset" )
212202
213203 } else {
214204 if len (args ) == 0 {
@@ -223,12 +213,11 @@ func (s *CLIService) ResetStats(ctx context.Context, args []string, all bool) er
223213 }
224214 }
225215
226- fmt .Printf ("Session records for %d programs reset\n " , len (args ))
227216 }
228217
229218 err := s .ServiceCmd .WriteToService ()
230219 if err != nil {
231- fmt .Printf ("Warning: Failed to notify service of reset : %v\n " , err )
220+ fmt .Printf ("Warning: Failed to notify service: %v\n " , err )
232221 }
233222
234223 return nil
@@ -279,11 +268,9 @@ func (s *CLIService) GetActiveSessions(ctx context.Context) error {
279268 return fmt .Errorf ("error getting active sessions: %w" , err )
280269 }
281270 if len (activeSessions ) == 0 {
282- fmt .Println ("No active sessions." )
283271 return nil
284272 }
285273
286- fmt .Println ("Active sessions: " )
287274 for _ , session := range activeSessions {
288275 duration := time .Since (session .StartTime )
289276 sessionDetails := fmt .Sprintf (" • %s - " , session .ProgramName )
@@ -299,3 +286,61 @@ func (s *CLIService) GetVersion() error {
299286 fmt .Println (s .Version )
300287 return nil
301288}
289+
290+ // Changes config to enable WakaTime with API key
291+ func (s * CLIService ) EnableWakaTime (apiKey , path string ) error {
292+ if s .Config .WakaTime .Enabled {
293+ return nil
294+ }
295+
296+ if apiKey != "" {
297+ s .Config .WakaTime .APIKey = apiKey
298+ }
299+
300+ if s .Config .WakaTime .APIKey == "" {
301+ return fmt .Errorf ("WakaTime API key required. Use flag: --api-key <key>" )
302+ }
303+
304+ if path != "" {
305+ s .Config .WakaTime .CLIPath = path
306+ }
307+
308+ if s .Config .WakaTime .CLIPath == "" {
309+ return fmt .Errorf ("wakatime-cli path required. Use flag: --set-path <path>" )
310+ }
311+
312+ s .Config .WakaTime .Enabled = true
313+
314+ if err := s .saveAndNotify (); err != nil {
315+ return err
316+ }
317+
318+ return nil
319+ }
320+
321+ // Disables WakaTime in config
322+ func (s * CLIService ) DisableWakaTime () error {
323+ if ! s .Config .WakaTime .Enabled {
324+ return nil
325+ }
326+
327+ s .Config .WakaTime .Enabled = false
328+
329+ if err := s .saveAndNotify (); err != nil {
330+ return err
331+ }
332+
333+ return nil
334+ }
335+
336+ // Sets wakatime-cli file path
337+ func (s * CLIService ) SetCLIPath (args []string ) error {
338+ newPath := args [0 ]
339+ s .Config .WakaTime .CLIPath = newPath
340+
341+ if err := s .saveAndNotify (); err != nil {
342+ return err
343+ }
344+
345+ return nil
346+ }
0 commit comments