Commits

andrea_crotti committed 1c240ad

refactor the argument parsing

  • Participants
  • Parent commits 97de8c1

Comments (0)

Files changed (1)

File tinkerer/cmdline.py

     :license: FreeBSD, see LICENSE file
 '''
 import argparse
+import logging
 import os
 import shutil
 import sphinx
 import sys
 from tinkerer import draft, page, paths, post, writer
 
+logger = logging.getLogger(__name__)
+
+
+def setup_logging():
+    root_logger = logging.getLogger()
+    root_logger.setLevel(logging.DEBUG)
 
 
 def setup(quiet=False, filename_only=False):
     if filename_only:
         print("conf.py")
     elif not quiet:
-        print("Your new blog is almost ready!")
-        print("You just need to edit a couple of lines in %s" % (os.path.relpath(paths.conf_file), ))
+        logger.info("Your new blog is almost ready!")
+        logger.info("You just need to edit a couple of lines in %s" % (os.path.relpath(paths.conf_file), ))
 
 
 
             print("New draft created as '%s'" % new_draft)
 
 
-
-def main(argv=None):
-    '''
-    Parses command line and executes required action.
-    '''
+def parse_arguments(argv):
     parser = argparse.ArgumentParser()
     group = parser.add_mutually_exclusive_group()
     group.add_argument("-s", "--setup", action="store_true", help="setup a new blog")
     group.add_argument("-f", "--filename", action="store_true",
             help="output filename only - useful to pipe Tinkerer commands")
 
-    command = parser.parse_args(argv)
+    return parser.parse_args(argv)
+    
+
+def main(argv=None):
+    '''
+    Parses command line and executes required action.
+    '''
+    command = parse_arguments(argv)
+    setup_logging()
 
     # tinkerer should be run from the blog root unless in setup mode
     if not command.setup and not os.path.exists(paths.conf_file):