old_contents: #!/usr/bin/python
  #coding:utf8
  
  __author__ = ['markshao']
  
  import optparse
  from pagrant import cmdoptions
  from pagrant.cmdparser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
  from pagrant.util import get_prog
  
  __all__ = ['Command']
  
  
  class Command(object):
      name = None
      usage = None
      hidden = None
      summary = ""
  
      def __init__(self):
          parser_kw = {
              'usage': self.usage,
              'prog': '%s %s' % (get_prog(), self.name),
              'formatter': UpdatingDefaultsHelpFormatter(),
              'add_help_option': False,
              'name': self.name,
              'description': self.__doc__,
          }
  
          self.parser = ConfigOptionParser(**parser_kw)
  
          # Commands should add options to this option group
          optgroup_name = '%s Options' % self.name.capitalize()
          self.cmd_opts = optparse.OptionGroup(self.parser, optgroup_name)
  
          # Add the general options
          gen_opts = cmdoptions.make_option_group(cmdoptions.general_group, self.parser)
          self.parser.add_option_group(gen_opts)
  
new_contents: #!/usr/bin/python
  #coding:utf8
  
  __author__ = ['markshao']
  
  import optparse
  from pagrant import cmdoptions
  from pagrant.cmdparser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
  from pagrant.util import get_prog
  
  __all__ = ['Command']
  
  
  class Command(object):
      name = None
      usage = None
      hidden = None
      summary = ""
  
      def __init__(self):
          parser_kw = {
              'usage': self.usage,
              'prog': '%s %s' % (get_prog(), self.name),
              'formatter': UpdatingDefaultsHelpFormatter(),
              'add_help_option': False,
              'name': self.name,
              'description': self.__doc__,
          }
  
          self.parser = ConfigOptionParser(**parser_kw)
  
          # Commands should add options to this option group
          optgroup_name = '%s Options' % self.name.capitalize()
          self.cmd_opts = optparse.OptionGroup(self.parser, optgroup_name)
  
          # Add the general options
          gen_opts = cmdoptions.make_option_group(cmdoptions.general_group, self.parser)
          self.parser.add_option_group(gen_opts)
  
      def setup_logging(self):
          pass
  
      def parse_args(self, args):
          # factored out for testability
          return self.parser.parse_args(args)
  
      def run(self, args):
          """
              The sub command class should overide this method
          """
          NotImplemented
  
      def execute(self, args=None):
          """
              The main interface for exectute the command
          """
          pass
subject: refactor the command code