Skip to content

Commit 85bc24c

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

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

examples/searchcommands_app/bin/simulate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class SimulateCommand(GeneratingCommand):
5353
from `tweets.csv`. Events are drawn at an average rate of 200 events per
5454
second for a duration of 30 seconds. Events are piped to the example
5555
`countmatches` command which adds a `word_count` field containing the number
56-
of words in the `text` of each tweet. The mean and standard deviation of the
57-
`word_count` are then computed by the builtin `stats` command.
56+
of words in the `text` field of each event. The mean and standard deviation
57+
of the `word_count` are then computed by the builtin `stats` command.
5858
5959
6060
"""

splunklib/searchcommands/__init__.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,35 @@ class sets this value unconditionally.
230230

231231
def dispatch(command_class, argv=sys.argv, input_file=sys.stdin, output_file=
232232
sys.stdout, module_name=None):
233-
""" TODO: Documentation
233+
""" Dispatches a search command
234+
235+
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):
248+
...
249+
250+
dispatch(CountMatchesCommand, module_name=__name__)
251+
```
252+
253+
Dispatches the CountMatchesCommand, if and only if `__name__` is equal to
254+
`__main__`.
255+
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`.
234262
235263
"""
236264
if module_name is not None and module_name != '__main__':
@@ -239,8 +267,8 @@ def dispatch(command_class, argv=sys.argv, input_file=sys.stdin, output_file=
239267
try:
240268
command_class().process(argv, input_file, output_file)
241269
except:
242-
import logging, traceback
243-
270+
import logging
271+
import traceback
244272
logging.fatal(traceback.format_exc())
245273

246274
return

0 commit comments

Comments
 (0)