-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Configure cement framework to CLI development
- Loading branch information
Showing
8 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .app import CommandLineInterface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from cement import App | ||
|
||
from .controllers import Base | ||
|
||
|
||
# Use `cement` framework to build a cli structure | ||
# See https://docs.builtoncement.com/getting-started/framework-overview#the-application-object. | ||
class CommandLineInterface(App): | ||
"""Package command line interface""" | ||
|
||
# Customize App behavior through Meta attributes | ||
# See https://cement.readthedocs.io/en/latest/api/core/foundation/. | ||
class Meta: | ||
# The name of the application | ||
# > Set on package inicialization through __main__ | ||
# label = <package_name> | ||
|
||
# The version of the application | ||
version = None | ||
|
||
# A handler class that implements the Config interface. | ||
# See https://docs.builtoncement.com/core-foundation/configuration-settings | ||
config_handler = 'yaml' | ||
|
||
# Extension used to identify application and plugin configuration files. | ||
config_file_suffix = '.yml' | ||
|
||
# Default configuration dictionary. Must be of type `dict` | ||
# config_defaults = None | ||
|
||
# A handler class that implements the Log interface. | ||
# See https://docs.builtoncement.com/core-foundation/logging-1 | ||
log_handler = 'colorlog' | ||
|
||
# A handler class that implements the Output interface | ||
# See https://docs.builtoncement.com/core-foundation/output-rendering | ||
output_handler = 'jinja2' | ||
|
||
# register handlers | ||
handlers = [ | ||
Base, | ||
] | ||
|
||
# List of additional framework extensions to load | ||
extensions = [ | ||
'colorlog', | ||
'jinja2', | ||
'yaml', | ||
] | ||
|
||
# Whether (or not) to call sys.exit() when close() is called | ||
exit_on_close = True | ||
|
||
@property | ||
def version(self): | ||
return self._meta.version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .base import Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from cement import Controller | ||
|
||
|
||
# Controlers are used on `cement` to manage available commands | ||
# See https://docs.builtoncement.com/core-foundation/controllers. | ||
class Base(Controller): | ||
""" | ||
Application root controller | ||
It's designed to handle the argument route at runtime | ||
(argument parsing, mapping sub-commands to controllers, etc) | ||
""" | ||
|
||
# Customize Controler behavior through Meta attributes | ||
# See https://cement.readthedocs.io/en/3.0/api/ext/ext_argparse/#cement.ext.ext_argparse.ArgparseController. | ||
class Meta: | ||
label = 'base' | ||
|
||
# text displayed at the top of --help output | ||
# description = '' # TODO | ||
|
||
# The text that is displayed at the bottom when --help is passed | ||
# epilog = '' # TODO | ||
|
||
# Arguments to pass to the argument_handler. | ||
# The format is a list of tuples which items are a ( list, dict ) | ||
arguments = [ | ||
(['-v', '--version'], {'action': 'version'}), | ||
] | ||
|
||
def _default(self): | ||
"""Default action if no sub-command is passed.""" | ||
|
||
self.app.args.print_help() | ||
|
||
def _pre_argument_parsing(self): | ||
self._parser.version = self.app.version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters