Skip to content

Commit d4b2dea

Browse files
author
David Noble
committed
Documentation update
1 parent 85bc24c commit d4b2dea

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

splunklib/searchcommands/__init__.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ class sets this value unconditionally.
217217
# Consider using the Splunk normalizeBoolean function
218218

219219

220-
221220
from __future__ import absolute_import
222221

223222
from .decorators import *
@@ -230,36 +229,43 @@ class sets this value unconditionally.
230229

231230
def dispatch(command_class, argv=sys.argv, input_file=sys.stdin, output_file=
232231
sys.stdout, module_name=None):
233-
""" Dispatches a search command
232+
""" Instantiates and executes a search command class
234233
235234
This function implements a [conditional script stanza](http://goo.gl/OFaox6)
236-
based on the value of `module_name`. If you would like the module calling
237-
this function to act as either a reusable module or a standalone program,
238-
call it at module scope and pass `__name__` as the value of `module_name`.
239-
Otherwise, if you wish this function to unconditionally execute a command,
240-
set the value of `module_name` to `None`. This is the default.
241-
242-
**Example:**
243-
244-
```python
245-
#!/usr/bin/env python
246-
...
247-
class CountMatchesCommand(StreamingCommand):
235+
based on the value of `module_name`::
236+
237+
if module_name is None or module_name == '__main__':
238+
# execute command
239+
240+
If you would like the module calling this function to act as either a
241+
reusable module or a standalone program, call it at module scope passing
242+
`__name__` as the value of `module_name`. Otherwise, if you wish this
243+
function to unconditionally instantiate and execute `command_class`, pass
244+
`None` as the value of `module_name`.
245+
246+
:param command_class: Class to instantiate and execute.
247+
:type command_class: ``.search_command.SearchCommand``
248+
:param argv: List of arguments to the command.
249+
:type argv: ``list``
250+
:param input_file: File from which the command will read data.
251+
:type input_file: ``file``
252+
:param output_file: File to which the command will write data.
253+
:type output_file: ``file``
254+
:param module_name: Name of the module calling dispatch or `None`.
255+
:type module_name: ``str``
256+
257+
**Example**::
258+
259+
#!/usr/bin/env python
248260
...
261+
class CountMatchesCommand(StreamingCommand):
262+
...
249263
250-
dispatch(CountMatchesCommand, module_name=__name__)
251-
```
264+
dispatch(CountMatchesCommand, module_name=__name__)
252265
253266
Dispatches the CountMatchesCommand, if and only if `__name__` is equal to
254267
`__main__`.
255268
256-
:param command_class: Search command class to instantiate and execute.
257-
:param argv: List of arguments to the command.
258-
:param input_file: File-like object from which the command will read data.
259-
:param output_file: File-like object to which the command will write data.
260-
:param module_name: Name of module calling dispatch (the value contained in
261-
`__name__`) or `None`.
262-
263269
"""
264270
if module_name is not None and module_name != '__main__':
265271
return

0 commit comments

Comments
 (0)