[meld] maint: Start to use click for the CLI



commit 0227be7eaa34afe7369e3759968357d313dfdfc7
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Wed Aug 20 08:02:18 2014 +1000

    maint: Start to use click for the CLI

 maint.py |   39 +++++++++++++++++++++++++--------------
 1 files changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/maint.py b/maint.py
index 2d7ea5d..4846984 100755
--- a/maint.py
+++ b/maint.py
@@ -5,6 +5,7 @@ import datetime
 import os
 import subprocess
 
+import click
 from jinja2 import Environment, Template
 
 import meld.conf
@@ -210,25 +211,35 @@ def get_tokens():
     }
 
 
-def format_news(jinja_env, tokens):
-    template = jinja_env.from_string(NEWS_TEMPLATE)
+def render_template(template):
+    tokens = get_tokens()
+    jinja_env = make_env()
+    template = jinja_env.from_string(template)
     return(template.render(tokens))
 
 
-def format_email(jinja_env, tokens):
-    template = jinja_env.from_string(EMAIL_TEMPLATE)
-    return(template.render(tokens))
+ click group()
+def cli():
+    pass
 
 
-def format_markdown(jinja_env, tokens):
-    template = jinja_env.from_string(MARKDOWN_TEMPLATE)
-    return(template.render(tokens))
+ cli command()
+def news():
+    news = render_template(NEWS_TEMPLATE)
+    click.echo(news)
 
 
-if __name__ == '__main__':
-    tokens = get_tokens()
-    jinja_env = make_env()
+ cli command()
+def email():
+    news = render_template(EMAIL_TEMPLATE)
+    click.echo(news)
+
+
+ cli command()
+def markdown():
+    news = render_template(MARKDOWN_TEMPLATE)
+    click.echo(news)
 
-    print(format_news(jinja_env, tokens))
-    print(format_email(jinja_env, tokens))
-    print(format_markdown(jinja_env, tokens))
+
+if __name__ == '__main__':
+    cli()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]