comparison docs/api/02_components/01_commands.md @ 513:dce482f7c62d

docs: Use fenced code block syntax.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 26 Jul 2015 09:54:19 -0700
parents 20fcadaaf871
children
comparison
equal deleted inserted replaced
512:32612333a367 513:dce482f7c62d
1 --- 1 ---
2 title: Chef Commands 2 title: Chef Commands
3 needs_pygments: true
4 --- 3 ---
5 4
6 To provide new `chef` commands, you need to override the `getCommands` method of 5 To provide new `chef` commands, you need to override the `getCommands` method of
7 your plugin, and return command instances: 6 your plugin, and return command instances:
8 7
9 8
10 {% highlight 'python' %} 9 ```python
11 class MyPlugin(PieCrustPlugin): 10 class MyPlugin(PieCrustPlugin):
12 name = 'myplugin' 11 name = 'myplugin'
13 12
14 def getCommands(self): 13 def getCommands(self):
15 return [ 14 return [
16 MyNewCommand()] 15 MyNewCommand()]
17 {% endhighlight %} 16 ```
18 17
19 18
20 To create a command class, inherit from the `ChefCommand` base class: 19 To create a command class, inherit from the `ChefCommand` base class:
21 20
22 {% highlight 'python' %} 21 ```python
23 from piecrust.commands.base import ChefCommand 22 from piecrust.commands.base import ChefCommand
24
25 23
26 class MyNewCommand(ChefCommand): 24 class MyNewCommand(ChefCommand):
27 def __init__(self): 25 def __init__(self):
28 super(MyNewCommand, self).__init__() 26 super(MyNewCommand, self).__init__()
29 self.name = 'foobar' 27 self.name = 'foobar'
32 def setupParser(self, parser, app): 30 def setupParser(self, parser, app):
33 parser.add_argument('thing') 31 parser.add_argument('thing')
34 32
35 def run(self, ctx): 33 def run(self, ctx):
36 print("Doing %s" % ctx.args.thing) 34 print("Doing %s" % ctx.args.thing)
37 {% endhighlight %} 35 ```
38 36
39 37
40 * The `name` will be used for command line invocation, _i.e._ your new command 38 * The `name` will be used for command line invocation, _i.e._ your new command
41 will be invoked with `chef foobar`. 39 will be invoked with `chef foobar`.
42 * The `description` will be used for help pages like `chef --help`. 40 * The `description` will be used for help pages like `chef --help`.