#!/usr/bin/env python
import sys
from timy import get_conn as gc, get_recent_tasks as grt, record_task
import timytask

# Creates a new task with the same tag as the last one.
def start_task_with_most_recent_tag(task):
    tag = "" # default tag in case there aren't any tasks

    conn = gc()
    recent_tasks=grt(conn, 1)
    if recent_tasks:
        last_task = recent_tasks.next()
        if last_task:
            tag = last_task.tag
            task = tag + ": " + task

    record_task(conn, task)

    return task

if __name__ == '__main__':
    task = ' '.join(sys.argv[1:])
    task = start_task_with_most_recent_tag(task)
    print "started task '%s'" % task