myapp.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from cement.core.foundation import CementApp
  2. from cement.core.controller import CementBaseController, expose
  3. from cement.core import handler
  4. class MyBaseController(CementBaseController):
  5. class Meta:
  6. label = 'base'
  7. class MySecondController(CementBaseController):
  8. class Meta:
  9. label = 'second'
  10. stacked_type = 'nested'
  11. stacked_on = 'base'
  12. description = 'this is the second controller namespace'
  13. arguments = [
  14. (['-f', '--foo'],
  15. dict(help='the notorious foo option', action='store')),
  16. (['extra_arguments'],
  17. dict(action='store', nargs='*')),
  18. ]
  19. @expose()
  20. def cmd1(self):
  21. print "Inside MySecondController.cmd1()"
  22. if self.app.pargs.extra_arguments:
  23. print "Extra Argument 0: %s" % self.app.pargs.extra_arguments[0]
  24. print "Extra Argument 1: %s" % self.app.pargs.extra_arguments[1]
  25. class MyApp(CementApp):
  26. class Meta:
  27. label = 'myapp'
  28. base_controller = MyBaseController
  29. def main():
  30. app = MyApp()
  31. handler.register(MySecondController)
  32. try:
  33. app.setup()
  34. app.run()
  35. finally:
  36. app.close()
  37. if __name__ == '__main__':
  38. main()