import sys
from cliff.app import App
from cliff.commandmanager import CommandManager
from cliff.lister import Lister
from usersettings import Settings
from pytivoclient.client import Client


class ClientApp(App):

    def __init__(self):
        super(ClientApp, self).__init__(
            description='pytivoclient app',
            version='0.1',
            command_manager=CommandManager('pytivoclient.app'),
            )
        self.parser.add_argument(
            '-n', '--hostname',
            action='store',
            help='TiVo hostname or IP address.',
            )
        self.parser.add_argument(
            '-m', '--media_access_key',
            action='store',
            help='Media Access Key.',
            metavar='KEY',
            )

    def initialize_app(self, argv):
        self.initialize_settings()
        self.client = Client(self.options.hostname,
                             self.options.media_access_key)

    def initialize_settings(self):
        self.settings = Settings('pytivoclient')
        self.settings.add_setting("hostname")
        self.settings.add_setting("media_access_key")
        self.settings.load_settings()
        for optname in ('hostname', 'media_access_key'):
            if not getattr(self.options, optname):
                optvalue = self.settings.get(optname)
                setattr(self.options, optname, optvalue)


class List(Lister):

    def take_action(self, parsed_args):
        return (('Title', 'Type'),
                ((i.title, i.content_type) for i in self.app.client.list())
                )


def main(argv=sys.argv[1:]):
    app = ClientApp()
    return app.run(argv)


if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))

@@ -418,37 +418,334 @@
           )%0A
+%0A
     
-    self.
+def build_option_parser(self, description, version, argparse_kwargs=None):%0A        parser = (super(ClientApp, self).%0A                  build_option_parser(description, version, argparse_kwargs))%0A        _remove_parser_argument(parser, '-q')%0A        _find_parser_argument(parser, '-v').default = 0%0A        
 parser.add_a
@@ -884,21 +884,16 @@
         
-self.
 parser.a
@@ -1043,32 +1043,54 @@
 ',%0A            )
+%0A        return parser
 %0A%0A    def initia
@@ -1874,16 +1874,16 @@
 list())%0A
-
         
@@ -1894,16 +1894,389 @@
     )%0A%0A%0A
+def _find_parser_argument(parser, option):%0A    gen = (a for a in parser._actions if option in a.option_strings)%0A    return next(gen, None)%0A%0Adef _remove_parser_argument(parser, option):%0A    action = _find_parser_argument(parser, option)%0A    for opt in action.option_strings:%0A        parser._option_string_actions.pop(opt, None)%0A    action.container._remove_action(action)%0A%0A%0A
 def main

fix up some cliff default global arguments