Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list-tags. #5

Merged
merged 1 commit into from
Mar 4, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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