add class attribute to disable REPL behaviour

This commit is contained in:
Romain Bignon 2010-10-08 10:51:42 +02:00
commit 0ebf8d579d
3 changed files with 16 additions and 4 deletions

View file

@ -85,6 +85,7 @@ class Monboob(ReplApplication):
'smtp': 'localhost', 'smtp': 'localhost',
'html': 0} 'html': 0}
CAPS = ICapMessages CAPS = ICapMessages
DISABLE_REPL = True
def add_application_options(self, group): def add_application_options(self, group):
group.add_option('-S', '--smtpd', help='run a fake smtpd server and set the port') group.add_option('-S', '--smtpd', help='run a fake smtpd server and set the port')
@ -98,7 +99,7 @@ class Monboob(ReplApplication):
def main(self, argv): def main(self, argv):
self.load_config() self.load_config()
return self.onecmd(' '.join(argv[1:])) return ReplApplication.main(self, argv)
def get_email_address_ident(self, msg, header): def get_email_address_ident(self, msg, header):
s = msg.get(header) s = msg.get(header)

View file

@ -28,13 +28,16 @@ class WeboobCli(ReplApplication):
APPNAME = 'weboob-cli' APPNAME = 'weboob-cli'
VERSION = '0.2' VERSION = '0.2'
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon' COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
SYNOPSIS = 'Usage: %prog [-dqv] [-b backends] [-cnfs] capability method [arguments..]\n'
SYNOPSIS += ' %prog [--help] [--version]'
DISABLE_REPL = True
def load_default_backends(self): def load_default_backends(self):
pass pass
def main(self, argv): def main(self, argv):
if len(argv) < 3: if len(argv) < 3:
print >>sys.stderr, "Syntax: %s capability command [args ..]" % argv[0] print >>sys.stderr, "Syntax: %s capability method [args ..]" % argv[0]
return 1 return 1
cap_s = argv[1] cap_s = argv[1]

View file

@ -52,6 +52,7 @@ class ReplApplication(Cmd, BaseApplication):
SYNOPSIS = 'Usage: %prog [-dqv] [-b backends] [-cnfs] [command [arguments..]]\n' SYNOPSIS = 'Usage: %prog [-dqv] [-b backends] [-cnfs] [command [arguments..]]\n'
SYNOPSIS += ' %prog [--help] [--version]' SYNOPSIS += ' %prog [--help] [--version]'
CAPS = None CAPS = None
DISABLE_REPL = False
# shell escape strings # shell escape strings
BOLD = '' BOLD = ''
@ -86,9 +87,13 @@ class ReplApplication(Cmd, BaseApplication):
if self._parser.description is None: if self._parser.description is None:
self._parser.description = '' self._parser.description = ''
help_str = u''
app_cmds, weboob_cmds, undoc_cmds = self.get_commands_doc() app_cmds, weboob_cmds, undoc_cmds = self.get_commands_doc()
help_str = '%s Commands:\n%s\n\n' % (self.APPNAME.capitalize(), '\n'.join(' %s' % cmd for cmd in sorted(app_cmds + undoc_cmds))) if len(app_cmds) > 0 or len(undoc_cmds) > 0:
help_str +='Weboob Commands:\n%s\n' % '\n'.join(' %s' % cmd for cmd in weboob_cmds) help_str += '%s Commands:\n%s\n\n' % (self.APPNAME.capitalize(), '\n'.join(' %s' % cmd for cmd in sorted(app_cmds + undoc_cmds)))
if not self.DISABLE_REPL:
help_str +='Weboob Commands:\n%s\n' % '\n'.join(' %s' % cmd for cmd in weboob_cmds)
self._parser.description += help_str self._parser.description += help_str
results_options = OptionGroup(self._parser, 'Results Options') results_options = OptionGroup(self._parser, 'Results Options')
@ -337,6 +342,9 @@ class ReplApplication(Cmd, BaseApplication):
ret = self.onecmd(cmd) ret = self.onecmd(cmd)
if ret: if ret:
return ret return ret
elif self.DISABLE_REPL:
self._parser.print_help()
self._parser.exit()
else: else:
self.intro += '\nLoaded backends: %s\n' % ', '.join(sorted(backend.name for backend in self.weboob.iter_backends())) self.intro += '\nLoaded backends: %s\n' % ', '.join(sorted(backend.name for backend in self.weboob.iter_backends()))
self._interactive = True self._interactive = True