#!/usr/bin/env python
"""
Script SIMPLEBLOG-RUN
Wrapper script for package SIMPLEBLOG
Copyright (C) 2012 by Peter A. Donis

Released under the GNU General Public License, Version 2
See the LICENSE and README files for more information
"""


global_optlist = (
    ("-c", "--configfile",
        { 'help': "the configuration file name" }
    ),
    ("-b", "--blogfile",
        { 'help': "the blog metadata file name" }
    ),
    ("-h", "--help",
        { 'action': 'store_true',
          'help': "show help information and exit" }
    )
)

global_arglist = (
    ("command", { 'nargs': "?", 'default': "" }),
)


if __name__ == '__main__':
    from plib.stdlib.options import prepare_specs, make_parser, invoke_parser
    
    global_optlist, global_arglist = prepare_specs(global_optlist, global_arglist)
    parser = make_parser(global_optlist, global_arglist,
        add_help=False)
    opts, args, result, remaining = invoke_parser(parser,
        global_optlist, global_arglist,
        incremental=True)
    
    cmd = args.command
    if cmd:
        from simpleblog.run import run
        run(cmd, parser, opts, global_optlist, result, remaining)
    elif opts.help:
        parser.print_help()
    else:
        from simpleblog import *
        from plib.stdlib.cmdline import run_shell
        run_shell()
