#!/usr/bin/env python
from sinor import posts
from sinor.config import config
import argparse

__author__ = 'mahnve'


def render_single():
    print(posts.render_markdown_page(args.content_files[0],
                                     args.template).encode('utf_8'))


def render_feed():
    print(posts.render_atom_feed(args.content_files).encode('utf_8'))


def render_archive():
    print(posts.render_post_list(args.content_files,
                                 args.template,
                                 args.limit).encode('utf_8'))


def render_mustache():
    print(posts.render_mustache_page(args.content_files[0]).encode('utf_8'))

if(__name__ == "__main__"):
    parser = argparse.ArgumentParser(
        description="A simple blog tool for static websites")

    parser.add_argument('-f',
                        help='path to config file',
                        default='sinor.toml')

    parser.add_argument("--type",
                        choices=['single', 'feed', 'archive', 'mustache'],
                        default="single")

    parser.add_argument("--template",
                        help="Mustache template file")

    parser.add_argument("--limit",
                        help="How many posts to include ",
                        type=int)

    parser.add_argument("content_files",
                        nargs='+',
                        help="Content file[s], Markdown or HTML")
    args = parser.parse_args()

    config.config_filename = args.f
    commands = {'single': render_single,
                'feed': render_feed,
                'archive': render_archive,
                'mustache': render_mustache}

    commands[args.type]()
