import logging
import argparse
import plaster
import hupper

logger = logging.getLogger(__name__)


class Command(object):
    def __init__(self, config, reload):
        self.config = config
        self.reload = reload

    def setup_logging(self):
        plaster.setup_logging(self.config)

    def setup_reloader(self):
        if self.reload:
            reloader = hupper.start_reloader("wsgiserve.main")
            reloader.watch_files([self.config])

    def get_wsgi_loader(self):
        loader = plaster.get_loader(self.config, protocols=["wsgi"])
        return loader

    def run(self):
        self.setup_logging()
        self.setup_reloader()
        loader = self.get_wsgi_loader()
        self.run_wsgi(loader)

    def run_wsgi(self, loader):
        app = loader.get_wsgi_app()
        server = loader.get_wsgi_server()
        server(app)


def setup_arguments(parser):
    parser.add_argument("config",
                        help="A path to the configuration file")
    parser.add_argument("--reload", action="store_true",
                        help="Use auto-restart file monitor")


def main():
    parser = argparse.ArgumentParser()
    setup_arguments(parser)
    args = parser.parse_args()
    command = Command(args.config, args.reload)
    command.run()

@@ -116,16 +116,48 @@
 bject):%0A
+    %22%22%22command of wsgiserve%22%22%22%0A%0A
     def 
@@ -188,16 +188,16 @@
 eload):%0A
-
         
@@ -268,32 +268,83 @@
 _logging(self):%0A
+        %22%22%22call setup_logging for self's config%22%22%22%0A
         plaster.
@@ -393,32 +393,88 @@
 reloader(self):%0A
+        %22%22%22setup reloader if reload option specified%22%22%22%0A
         if self.
@@ -616,32 +616,81 @@
 i_loader(self):%0A
+        %22%22%22get wsgi loader from self's config%22%22%22%0A
         loader =
@@ -776,32 +776,58 @@
  def run(self):%0A
+        %22%22%22run command%22%22%22%0A
         self.set
@@ -968,24 +968,65 @@
 f, loader):%0A
+        %22%22%22serve wsgi app with loader%22%22%22%0A
         app 
@@ -1138,24 +1138,61 @@
 ts(parser):%0A
+    %22%22%22setup arguments for parser%22%22%22%0A
     parser.a
@@ -1395,24 +1395,24 @@
 monitor%22)%0A%0A%0A
-
 def main():%0A
@@ -1411,16 +1411,41 @@
 main():%0A
+    %22%22%22main procedure%22%22%22%0A
     pars

add doc strings