#!/usr/bin/python


'''
usage: (assumes .index.py is symlinked to todo)
    todo ls - lists all items in todays todo file
    todo a "[NUM].item" - add an item to NUM, or to the end by default
    todo d NUM - delete item numbered NUM
    todo e - edit the todo.md file

    //TODO, features to be added
    todo init <path> - init git repo to <path> and change todo_md_dir in config
    versioning with git
    add Makefile for the symlink

    //TODO: in vim:
    add a function to quickly open the previous todo.md or the next with a touch of a button

'''

from os import path
import json
import argparse
import todo_md.commands as commands
import todo_md.utils as utils

from app.config import TODO_DIRECTORY


def parse_args():
    parser = argparse.ArgumentParser(description='basic todo.txt command line utility')
    parser.add_argument('command')
    parser.add_argument('command_arguments', nargs='*')
    return parser.parse_args()

def err(directory):
    print 'this command does not exist yet'

if __name__ == '__main__':


    args = parse_args()

    # get the path to the current todo file. create a new todo file if the file for today
    # does not exists, and copy previous days contents to today
    todo_directory = path.expanduser(TODO_DIRECTORY)
    todo_path = utils.get_todo_path(todo_directory)

    # execute the command
    getattr(commands, args.command, err)(todo_path, args.command_arguments)

    # re-number every item in current todo file
    utils.reorganize_todo(todo_path)
