Skip to content

Commit

Permalink
Merge pull request #5 from ways/master
Browse files Browse the repository at this point in the history
Add list-tags.
  • Loading branch information
robinhouston committed Mar 4, 2015
2 parents 0b6caf8 + 370486d commit d28205f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions freck
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Freckle(object):
self.url_base = "https://{subdomain}.letsfreckle.com/api/".format(
subdomain=self.config["subdomain"])
self._load_projects()
self._load_tags()

def _generate_config(self):
"""Generate configuration file interactively; called if we don’t have one yet.
Expand Down Expand Up @@ -188,6 +189,31 @@ class Freckle(object):
else:
print " " + project.encode("utf-8")
print

def _load_tags(self):
"""Load the list of tags.
"""
if hasattr(self, "tags"):
# Tags are already loaded
return

self.tags = {}
for t in self.api("tags"):
tag = t["tag"]
self.tags[tag["name"]] = tag["id"]

def list_tags(self):
"""Print a list of all tags.
"""
print "Tags for {subdomain}.letsfreckle.com:".format(
subdomain=self.config["subdomain"])

for tag in self.tags:
if tag == self.config.get("tag"):
print "* " + tag.encode("utf-8")
else:
print " " + tag.encode("utf-8")
print

def create_entry(self, time, description=None, tags=None, project_name=None, date=None, user=None):
"""Create a new time-tracking entry.
Expand Down Expand Up @@ -233,6 +259,10 @@ parser.add_option("-l", "--list-projects",
action="store_true",
help="list all available projects")

parser.add_option("--list-tags",
action="store_true",
help="list all available tags")

parser.add_option("-t", "--tags",
action="store",
help="additional tags, overriding the default if any")
Expand Down Expand Up @@ -279,6 +309,12 @@ if options.list_projects:
Freckle().list_projects()
sys.exit(0)

if options.list_tags:
if args:
parser.error("Unexpected argument following --list-tags: " + args[0])
Freckle().list_tags()
sys.exit(0)

freckle = Freckle()
done_something = False
if options.create:
Expand Down

0 comments on commit d28205f

Please sign in to comment.