Skip to content

Commit 6ca8adb

Browse files
committed
feat: migrate activities to views
Migrate activities CLI action to view pattern
1 parent 7f606c1 commit 6ca8adb

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/hamster-cli.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ class HamsterView(abc.ABC):
231231
def current(self, action):
232232
pass
233233

234+
def activities(self, facts):
235+
pass
236+
234237
class HamsterViewText(HamsterView):
235238

236239
def current(self, action):
@@ -240,6 +243,10 @@ def current(self, action):
240243
else:
241244
print((_("No activity")))
242245

246+
def activities(self, facts):
247+
for activity in facts:
248+
print("{}@{}".format(activity['name'], activity['category']))
249+
243250
class HamsterViewJSON(HamsterView):
244251

245252
def _dump_fact(self, fact):
@@ -259,6 +266,10 @@ def current(self, action):
259266
output=self._dump_fact(action)
260267
print(json.dumps(output))
261268

269+
def activities(self, facts):
270+
output = [{"name":activity['name'], "category":activity['category']}
271+
for activity in facts]
272+
print(json.dumps(output))
262273
class HamsterCli(object):
263274
"""Command line interface."""
264275

@@ -335,8 +346,7 @@ def _activities(self, search=""):
335346
def activities(self, *args):
336347
'''Print the names of all the activities.'''
337348
search = args[0] if args else ""
338-
for activity in self.storage.get_activities(search):
339-
print("{}@{}".format(activity['name'], activity['category']))
349+
self.view.activities(self.storage.get_activities(search))
340350

341351
def categories(self, *args):
342352
'''Print the names of all the categories.'''

0 commit comments

Comments
 (0)