@@ -231,6 +231,10 @@ def __init__(self):
231231 self .storage = client .Storage ()
232232
233233
234+ def setFormat (self , format :str ):
235+ self .format = format
236+
237+
234238 def assist (self , * args ):
235239 assist_command = args [0 ] if args else ""
236240
@@ -318,11 +322,19 @@ def list(self, *times):
318322 def current (self , * args ):
319323 """prints current activity. kinda minimal right now"""
320324 facts = self .storage .get_todays_facts ()
321- if facts and not facts [- 1 ].end_time :
322- print ("{} {}" .format (str (facts [- 1 ]).strip (),
323- facts [- 1 ].delta .format (fmt = "HH:MM" )))
325+
326+ if not self .format or self .format == 'text' :
327+ if facts and not facts [- 1 ].end_time :
328+ print ("{} {}" .format (str (facts [- 1 ]).strip (),
329+ facts [- 1 ].delta .format (fmt = "HH:MM" )))
330+ else :
331+ print ((_ ("No activity" )))
324332 else :
325- print ((_ ("No activity" )))
333+ fact = []
334+ if facts :
335+ fact = [facts [- 1 ]]
336+ now = dt .datetime .now ()
337+ reports .simple (fact , now , now , self .format )
326338
327339
328340 def search (self , * args ):
@@ -467,6 +479,10 @@ def version(self):
467479 choices = ('DEBUG' , 'INFO' , 'WARNING' , 'ERROR' , 'CRITICAL' ),
468480 default = 'WARNING' ,
469481 help = "Set the logging level (default: %(default)s)" )
482+ parser .add_argument ("-f" , "--format" ,
483+ choices = ('text' , 'html' , 'tsv' , 'xml' , 'ical' ),
484+ default = '' ,
485+ help = "Set output format (default: %(default)s)" )
470486 parser .add_argument ("action" , nargs = "?" , default = "overview" )
471487 parser .add_argument ('action_args' , nargs = argparse .REMAINDER , default = [])
472488
@@ -488,6 +504,8 @@ def version(self):
488504 else :
489505 action = args .action
490506
507+ hamster_client .setFormat (args .format )
508+
491509 if action in ("about" , "add" , "edit" , "overview" , "preferences" ):
492510 if action == "add" and args .action_args :
493511 assert not unknown_args , "unknown options: {}" .format (unknown_args )
0 commit comments