Skip to content

Commit

Permalink
partially realign CLI actions with Hamster
Browse files Browse the repository at this point in the history
  • Loading branch information
GeraldJansen committed Feb 12, 2020
1 parent 77761ff commit 0653a9a
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/hamster-lite
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ import argparse
import re
import datetime as dt

import hamster_lite
from hamster_lite import reports
from hamster_lite import logger as hamster_logger
from hamster_lite.lib import default_logger, Fact, stuff, DATE_FMT
from hamster_lite.lib.runtime import dialogs
from hamster_lite.lib.runtime import dialogs, runtime
from hamster_lite.main import HamsterLite
import hamster_lite.storage as db

Expand Down Expand Up @@ -90,19 +91,15 @@ class HamsterClient(object):
app = HamsterLite()
app.run()

def prefs(self, *args):
from gi.repository import Gtk as gtk
dialogs.prefs.show()
gtk.main()

def add(self, *args):
from gi.repository import Gtk as gtk
dialogs.edit.show()
gtk.main()

def track(self, *args):
"""same as start"""
self.start(*args)
def preferences(self, *args):
from gi.repository import Gtk as gtk
dialogs.prefs.show()
gtk.main()

def start(self, *args):
'''Start a new activity.'''
Expand Down Expand Up @@ -240,8 +237,7 @@ class HamsterClient(object):
print()

def version(self):
from hamster_lite.lib.runtime import runtime
print(runtime.version)
print(hamster_lite.__version__)

if __name__ == '__main__':
from hamster_lite.lib import i18n
Expand All @@ -250,7 +246,7 @@ if __name__ == '__main__':
usage = _(
"""
Actions:
* start / track <activity> [start-time] [end-time]: Track an activity
* add [activity [[start-time] [end-time]]]: Add an activity
* stop: Stop tracking current activity.
* list [start-date [end-date]]: List activities
* search [terms] [start-date [end-date]]: List activities matching a search
Expand All @@ -261,7 +257,7 @@ Actions:
* activities: List all the activities names, one per line.
* categories: List all the categories names, one per line.
* overview / add / prefs: launch specific window
* overview / add / preferences: launch specific window
* version: Show the hamster-lite version
Time formats:
Expand Down Expand Up @@ -306,8 +302,14 @@ Example usage:
# hamster_logger for the rest
hamster_logger.setLevel(args.log_level)

command = args.action
if hasattr(hamster_client, command):
getattr(hamster_client, command)(*args.action_args)
if (args.action == 'add' and args.action_args) or args.action == 'track':
action = "start" # aliases
elif args.action == "prefs": # for backward compatibility
action = "preferences"
else:
action = args.action

if hasattr(hamster_client, action):
getattr(hamster_client, action)(*args.action_args)
else:
sys.exit(usage % {'prog': sys.argv[0]})

0 comments on commit 0653a9a

Please sign in to comment.