summaryrefslogtreecommitdiff
path: root/example.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-02-19 12:16:36 +0000
committerLars Wirzenius <liw@liw.fi>2011-02-19 12:16:36 +0000
commit3d028e8059cfee956f03e32f06d1a59248803635 (patch)
tree7949c29450eb23fc78960c83ab45a2c5bee256b2 /example.py
parent47d96d7d6150c3a74589f00e1a728bfc12193b58 (diff)
downloadcliapp-3d028e8059cfee956f03e32f06d1a59248803635.tar.gz
Improve docstring and example.
Some day it might be good to have a separate tutorial, but for now, the docstring will suffice.
Diffstat (limited to 'example.py')
-rw-r--r--example.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/example.py b/example.py
index dd0fac1..0c60ae7 100644
--- a/example.py
+++ b/example.py
@@ -14,7 +14,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-'''Example for cliapp framework.'''
+'''Example for cliapp framework.
+
+This implements an fgrep-like utility.
+
+'''
import cliapp
@@ -27,10 +31,18 @@ class ExampleApp(cliapp.Application):
def add_settings(self):
self.add_string_list_setting(['pattern', 'e'], 'pattern to search for')
+ # We override process_inputs to be able to do something after the last
+ # input line.
+ def process_inputs(self, args):
+ self.matches = 0
+ cliapp.Application.process_inputs(self, args)
+ self.output.write('There were %s matches.\n' % self.matches)
+
def process_input_line(self, name, line):
for pattern in self['pattern']:
if pattern in line:
- self.output.write(line)
+ self.output.write('%s:%s: %s' % (name, self.lineno, line))
+ self.matches += 1
ExampleApp(version='0.1.2').run()