Skip to content

Commit 5b8a091

Browse files
committed
feat: use reports multiple formats for current
Use `reports` module that provide multiple output formats to format output of `current` action.
1 parent 21facca commit 5b8a091

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/usr/bin/env python2
22
import distutils
33
import os
4-
from distutils.core import setup
54
from distutils import sysconfig
5+
try:
6+
from setuptools import setup
7+
except ImportError:
8+
from distutils.core import setup
69

710
data_dir = os.path.join(sysconfig.get_python_lib(), "hamster", "data")
811

src/hamster-cli.py

100644100755
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)