Back to index

python-cliapp  1.20120630
example2.py
Go to the documentation of this file.
00001 # Copyright (C) 2011  Lars Wirzenius
00002 # 
00003 # This program is free software; you can redistribute it and/or modify
00004 # it under the terms of the GNU General Public License as published by
00005 # the Free Software Foundation; either version 2 of the License, or
00006 # (at your option) any later version.
00007 # 
00008 # This program is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 # GNU General Public License for more details.
00012 # 
00013 # You should have received a copy of the GNU General Public License along
00014 # with this program; if not, write to the Free Software Foundation, Inc.,
00015 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016 
00017 
00018 '''Example for cliapp framework.
00019 
00020 Greet or insult people.
00021 
00022 '''
00023 
00024 
00025 import cliapp
00026 import logging
00027 
00028 
00029 class ExampleApp(cliapp.Application):
00030 
00031     cmd_synopsis = {
00032         'greet': '[USER]...',
00033         'insult': '[USER]...',
00034     }
00035     
00036     def cmd_greet(self, args):
00037         '''Greet the user.
00038         
00039         The user is treated to a a courteus,
00040         but terse form of greeting.
00041         
00042         '''
00043         for arg in args:
00044             self.output.write('greetings, %s\n' % arg)
00045             
00046     def cmd_insult(self, args):
00047         '''Insult the user.
00048         
00049         Sometimes, though rarely, it happens that a user is really a bit of 
00050         a prat, and needs to be told off. This is the command for that.
00051         
00052         '''
00053         for arg in args:
00054             self.output.write('you suck, %s\n' % arg)
00055     
00056     
00057 app = ExampleApp(version='0.1.2', description='''
00058 Greet the user.
00059 Or possibly insult them. User's choice.
00060 ''',
00061 epilog='''
00062 This is the epilog.
00063 
00064 I hope you like it.
00065 ''')
00066 app.run()
00067