#!/usr/bin/env python
#
# The MIT License (MIT)
#
# Copyright (c) 2015 Corrado Ubezio
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


'''Command Line Interfaces utilities
'''


def cfg_file_arg(prog_version, prog_usage, default_cfg_file):
    '''Parse cli arguments matching -c or --cfg option.

    Returns args.cfg_file.
    '''
    from argparse import ArgumentParser, RawTextHelpFormatter

    parser = ArgumentParser(description=prog_usage,
                             formatter_class=RawTextHelpFormatter)
    print '%s v%s (C) 2015' % (parser.prog, prog_version)

    desc = "read the configuration from the CFG JSON file"
    parser.add_argument('-c', '--cfg', dest='cfg_file',
                            help=desc,
                            default=default_cfg_file)
    parser.add_argument('-v', '--version', action='version',
                        version='%%(prog)s %s' % prog_version)
    args = parser.parse_args()
    return args


if __name__ == "__main__":
    options = cfg_file_arg('X.Y', 'Usage string', 'default_cfg_file')
    print options.cfg_file
@@ -1283,27 +1283,121 @@
 ing 
--c or --cfg opt
+the following options:%0A         -h or --help%0A         -c or --cfg%0A         -d or --debug%0A         -v or --vers
 ion
-.
 %0A%0A  
@@ -1414,18 +1414,8 @@
 args
-.cfg_file.
 %0A   
@@ -1868,16 +1868,186 @@
 g_file)%0A
+    parser.add_argument('-d', '--debug', dest='debug', action='store_true',%0A                            help='enable debug',%0A                            default='False')%0A
     pars
@@ -2322,20 +2322,149 @@
 int 
-options.cfg_file
+'Configuration file:', options.cfg_file%0A    if options.debug is True:%0A        print 'Debug is Enable'%0A    else:%0A        print 'Debug is Disable'%0A

Add debug switch in cfg_file_arg function