#!/usr/bin/env python3 """A simple blog generator with Pandoc as backend.""" # TODO: auto retouch: prompt for git commit amend after touching # (display commit message to avoid amending the wrong commit) # pylint: disable=too-many-lines import argparse import dateutil.parser from utils import utils from cli import cli def main(): """CLI interface.""" description = "Simple blog generator in Python with Pandoc as backend." parser = argparse.ArgumentParser(description=description) subparsers = parser.add_subparsers(dest="action") subparsers.required = True parser_new_post = subparsers.add_parser( "new_post", aliases=["n", "new"], description="Create a new post with metadata pre-filled.") parser_new_post.add_argument("title", help="title of the new post") parser_new_post.set_defaults(func=cli.new_post_cli) parser_new_post = subparsers.add_parser( "touch", aliases=["t", "tou"], description="""Touch an existing post, i.e., update its timestamp to current time. Why is this ever useful? Well, the timestamp filled in by new_post is the time of creation, but one might spend several hours after the creation of the file to finish the post. Sometimes the post is even created on one day and finished on another (say created at 11pm and finished at 1am). Therefore, one may want to retouch the timestamp before publishing.""") parser_new_post.add_argument("filename", help="path or basename of the source file, " "e.g., 2015-05-05-new-blog-new-start.md") parser_new_post.set_defaults(func=cli.touch_cli) parser_generate = subparsers.add_parser( "generate", aliases=["g", "gen"], description="Generate new or changed objects.") parser_generate.set_defaults(func=cli.generate) parser_regenerate = subparsers.add_parser( "regenerate", aliases=["r", "regen"], description="Regenerate the entire blog afresh.") parser_regenerate.set_defaults(func=cli.regenerate) parser_new_post = subparsers.add_parser( "preview", aliases=["p", "pre"], description="Serve the blog locally and auto regenerate upon changes.") parser_new_post.set_defaults(func=cli.preview) parser_new_post = subparsers.add_parser( "deploy", aliases=["d", "dep"], description="Deploy build/ to origin/master without regenerating.") parser_new_post.set_defaults(func=cli.deploy) parser_new_post = subparsers.add_parser( "gen_deploy", aliases=["gd", "gendep"], description="Rebuild entire blog and deploy build/ to origin/master.") parser_new_post.set_defaults(func=cli.gen_deploy) parser_new_post = subparsers.add_parser( "edit", aliases=["e", "ed"], description="Bring up post selector to select post for editing.") parser_new_post.set_defaults(func=cli.edit_existing_post) with utils.init_colorama(): args = parser.parse_args() returncode = args.func(args) exit(returncode) if __name__ == '__main__': main()