Skip to content

Commit

Permalink
Update Cement Templates for Cement 2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
derks committed Jul 21, 2016
1 parent b580f49 commit 1f27ab3
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 17 deletions.
3 changes: 1 addition & 2 deletions cement-app/@module@/cli/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# All built-in application controllers should be imported, and registered
# in this file in the same way as @class_prefix@BaseController.

from cement.core import handler
from @module@.cli.controllers.base import @class_prefix@BaseController

def load(app):
handler.register(@class_prefix@BaseController)
app.handler.register(@class_prefix@BaseController)
4 changes: 2 additions & 2 deletions cement-app/@module@/cli/controllers/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""@project@ base controller."""

from cement.core.controller import CementBaseController, expose
from cement.ext.ext_argparse import ArgparseController, expose

class @class_prefix@BaseController(CementBaseController):
class @class_prefix@BaseController(ArgparseController):
class Meta:
label = 'base'
description = '@description@'
Expand Down
3 changes: 3 additions & 0 deletions cement-app/@module@/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Meta:
# Internal templates (ship with application code)
template_module = '@[email protected]'

# call sys.exit() when app.close() is called
exit_on_close = True


class @class_prefix@TestApp(@class_prefix@App):
"""A test app that is better suited for testing."""
Expand Down
9 changes: 4 additions & 5 deletions cement-app/@module@/cli/plugins/example.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Example Plugin for @project@."""

from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook
from cement.ext.ext_argparse import ArgparseController, expose

def example_plugin_hook(app):
# do something with the ``app`` object here.
pass

class ExamplePluginController(CementBaseController):
class ExamplePluginController(ArgparseController):
class Meta:
# name that the controller is displayed at command line
label = 'example'
Expand Down Expand Up @@ -44,7 +43,7 @@ def example_plugin_command(self):

def load(app):
# register the plugin class.. this only happens if the plugin is enabled
handler.register(ExamplePluginController)
app.handler.register(ExamplePluginController)

# register a hook (function) to run after arguments are parsed.
hook.register('post_argument_parsing', example_plugin_hook)
app.hook.register('post_argument_parsing', example_plugin_hook)
2 changes: 1 addition & 1 deletion cement-app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cement>=2.6.0
cement>=2.10.0
7 changes: 4 additions & 3 deletions cement-app/tests/cli/test_@[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class CliTestCase(test.@class_prefix@TestCase):
def test_@module@_cli(self):
self.app.setup()
self.app.run()
self.app.close()
argv = ['--foo=bar']
with self.make_app(argv=argv) as app:
app.run()
self.eq(app.pargs.foo, 'bar')
3 changes: 1 addition & 2 deletions cement-plugin/@package@/cli/plugins/@[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""

from cement.core import handler
from cement.core.controller import CementBaseController, expose

class @class_prefix@PluginController(CementBaseController):
Expand All @@ -16,5 +15,5 @@ class Meta:
description = "@plugin.capitalize@ Plugin for @project@."

def load(app):
handler.register(@class_prefix@PluginController)
app.handler.register(@class_prefix@PluginController)

10 changes: 8 additions & 2 deletions cement-script/@[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@

from cement.core.foundation import CementApp
from cement.utils.misc import init_defaults
from cement.core.controller import CementBaseController, expose
from cement.ext.ext_argparse import ArgparseController, expose
from cement.core.exc import FrameworkError, CaughtSignal


defaults = init_defaults('@module@')
defaults['@module@'] = dict(
debug=False,
foo='bar',
)

class @class_prefix@BaseController(CementBaseController):

class @class_prefix@BaseController(ArgparseController):
class Meta:
label = 'base'
description = '@description@'
Expand All @@ -30,11 +32,14 @@ class Meta:
def default(self):
print("Inside @[email protected]()")


class @class_prefix@App(CementApp):
class Meta:
label = '@module@'
base_controller = @class_prefix@BaseController
config_defaults = defaults
exit_on_close = True


def main():
with @class_prefix@App() as app:
Expand All @@ -51,5 +56,6 @@ def main():
print('CaughtSignal > %s' % e)
app.exit_code = 0


if __name__ == '__main__':
main()

0 comments on commit 1f27ab3

Please sign in to comment.