#!/usr/bin/env python

import argparse
import logging
import sys

from clean import clean
from smudge import smudge


logger = logging.getLogger()
logging_configured = False


def configure_logging(args):
    global logging_configured
    if not logging_configured:
        logger.setLevel(logging.DEBUG)
        console_log = logging.StreamHandler(stream=sys.stderr)
        logger.addHandler(console_log)
        logging_configured = True


def main():
    parser = argparse.ArgumentParser(
            description='Manage dot files with secrets')
    subparsers = parser.add_subparsers()

    file_parser = argparse.ArgumentParser(add_help=False)
    file_parser.add_argument('--input', metavar='FILE',
            type=argparse.FileType('r'), default=sys.stdin,
            help="Read input from FILE, default is '-' stdin")
    file_parser.add_argument('--output', metavar='FILE',
            type=argparse.FileType('w'), default=sys.stdout,
            help="Write output from FILE, default is '-' stdout")

    parser_clean = subparsers.add_parser('clean', parents=[file_parser])
    parser_clean.add_argument('--config', metavar='FILE',
            help='Load config from FILE')
    parser_clean.add_argument('type')
    parser_clean.set_defaults(func=clean)

    parser_smudge = subparsers.add_parser('smudge', parents=[file_parser])
    parser_smudge.add_argument('--store', metavar='FILE',
            help='Load secrets from FILE')
    parser_smudge.add_argument('type')
    parser_smudge.set_defaults(func=smudge)
    
    args=parser.parse_args()
    configure_logging(args)
    args.func(args)


if __name__ == '__main__':
    main()

@@ -140,16 +140,17 @@
 ogger()%0A
+%0A
 logging_
@@ -169,16 +169,225 @@
  False%0A%0A
+log_levels = %7B%0A        'debug'    : logging.DEBUG,%0A        'info'     : logging.INFO,%0A        'warning'  : logging.WARNING,%0A        'error'    : logging.ERROR,%0A        'critical' : logging.CRITICAL%0A        %7D%0A%0A
 %0Adef con
@@ -496,26 +496,39 @@
 evel(log
-ging.DEBUG
+_levels%5Bargs.log_level%5D
 )%0A      
@@ -766,16 +766,250 @@
 crets')%0A
+    parser.add_argument('--log-level', metavar='LEVEL',%0A            choices=log_levels.keys(), default='warning',%0A            help=%22set logging to LEVEL, where LEVEL is %22%0A                 %22one of %25(choices)s; default is %25(default)s%22)%0A
     subp
@@ -1234,17 +1234,17 @@
   help=%22
-R
+r
 ead inpu
@@ -1415,17 +1415,17 @@
   help=%22
-W
+w
 rite out
@@ -1609,25 +1609,25 @@
       help='
-L
+l
 oad config f
@@ -1869,17 +1869,17 @@
   help='
-L
+l
 oad secr

Add arguments for logging