Arguments
Last updated
from cement import App
with App('myapp') as app:
# add arguments before app.run()
app.args.add_argument('-f', '--foo',
action='store',
dest='foo')
# run the application (parses arguments)
app.run()$ python myapp.py --help
usage: myapp [-h] [-d] [-q] [-f FOO]
optional arguments:
-h, --help show this help message and exit
-d, --debug full application debug mode
-q, --quiet suppress all console output
-f FOO, --foo FOOfrom cement import App
with App('myapp') as app:
# add arguments before app.run()
app.args.add_argument('-f', '--foo',
action='store',
dest='foo')
# run the application (parses arguments)
app.run()
# test if argument was passed
if app.pargs.foo is not None:
print('Foo => %s ' app.pargs.foofrom cement import App
from cement.core.arg import ArgumentHandler
class MyArgumentHandler(ArgumentHandler):
class Meta:
label = 'my_argument_handler'
# do something to implement the interface
class MyApp(App):
class Meta:
label = 'myapp'
argument_handler = 'my_argument_handler'
handlers = [
MyArgumentHandler,
]