Skip to content

Commit

Permalink
feat: use reports multiple formats for current
Browse files Browse the repository at this point in the history
Use `reports` module that provide multiple output formats to format
output of `current` action.
  • Loading branch information
rafaltrojniak committed Jun 7, 2020
1 parent 21facca commit 34d3a72
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/hamster-cli.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ def __init__(self):
self.storage = client.Storage()


def setFormat(self, format:str):
self.format = format


def assist(self, *args):
assist_command = args[0] if args else ""

Expand Down Expand Up @@ -318,11 +322,20 @@ def list(self, *times):
def current(self, *args):
"""prints current activity. kinda minimal right now"""
facts = self.storage.get_todays_facts()
if facts and not facts[-1].end_time:
print("{} {}".format(str(facts[-1]).strip(),
facts[-1].delta.format(fmt="HH:MM")))

from pprint import pprint
if not self.format or self.format == 'text':
if facts and not facts[-1].end_time:
print("{} {}".format(str(facts[-1]).strip(),
facts[-1].delta.format(fmt="HH:MM")))
else:
print((_("No activity")))
else:
print((_("No activity")))
fact=[]
if facts:
fact = [facts[-1]]
now = dt.datetime.now()
reports.simple(fact, now, now, self.format)


def search(self, *args):
Expand Down Expand Up @@ -467,6 +480,10 @@ def version(self):
choices=('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'),
default='WARNING',
help="Set the logging level (default: %(default)s)")
parser.add_argument("-f", "--format",
choices=('text', 'html', 'tsv', 'xml', 'ical'),
default='',
help="Set output format (default: %(default)s)")
parser.add_argument("action", nargs="?", default="overview")
parser.add_argument('action_args', nargs=argparse.REMAINDER, default=[])

Expand All @@ -488,6 +505,8 @@ def version(self):
else:
action = args.action

hamster_client.setFormat(args.format)

if action in ("about", "add", "edit", "overview", "preferences"):
if action == "add" and args.action_args:
assert not unknown_args, "unknown options: {}".format(unknown_args)
Expand Down

0 comments on commit 34d3a72

Please sign in to comment.