Mercurial > piecrust2
view docs/api/02_components/01_commands.md @ 853:f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
The asset pipeline is still the only function pipeline at this point.
* No more `QualifiedPage`, and several other pieces of code deleted.
* Data providers are simpler and more focused. For instance, the page iterator
doesn't try to support other types of items.
* Route parameters are proper known source metadata to remove the confusion
between the two.
* Make the baker and pipeline more correctly manage records and record
histories.
* Add support for record collapsing and deleting stale outputs in the asset
pipeline.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 21 May 2017 00:06:59 -0700 |
parents | dce482f7c62d |
children |
line wrap: on
line source
--- title: Chef Commands --- To provide new `chef` commands, you need to override the `getCommands` method of your plugin, and return command instances: ```python class MyPlugin(PieCrustPlugin): name = 'myplugin' def getCommands(self): return [ MyNewCommand()] ``` To create a command class, inherit from the `ChefCommand` base class: ```python from piecrust.commands.base import ChefCommand class MyNewCommand(ChefCommand): def __init__(self): super(MyNewCommand, self).__init__() self.name = 'foobar' self.description = "Does some foobar thing." def setupParser(self, parser, app): parser.add_argument('thing') def run(self, ctx): print("Doing %s" % ctx.args.thing) ``` * The `name` will be used for command line invocation, _i.e._ your new command will be invoked with `chef foobar`. * The `description` will be used for help pages like `chef --help`. * The `setupParser` method passes an `argparse.ArgumentParser` and a `PieCrust` application. You're supposed to setup the syntax for your commend there. * The `run` method is called when your command is executed. The `ctx` object contains a couple useful things, among others: * `args` is the namespace obtained from running `parse_args`. It has all the values of the arguments for your command. * `app` is the instance of the current `PieCrust` application. * For the other things, check-out `piecrust.commands.base.CommandContext`.