From 1df25181222459bd92ad64296b6bec05b842b981 Mon Sep 17 00:00:00 2001 From: "Jeroen van Meeuwen (Kolab Systems)" Date: Wed, 2 Mar 2011 13:37:07 +0000 Subject: Bail out with a message on --help if no command is given on the CLI --- pykolab/cli/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pykolab/cli/__init__.py b/pykolab/cli/__init__.py index 40fb20b..defa462 100644 --- a/pykolab/cli/__init__.py +++ b/pykolab/cli/__init__.py @@ -47,7 +47,11 @@ class Cli(object): self.conf.finalize_conf() # The first argument has to be a command - action = self.conf.args.pop(0) + try: + action = self.conf.args.pop(0) + except IndexError, e: + self.no_command() + action_function = action.replace('-','_') action_components = action.split('-') @@ -66,6 +70,10 @@ class Cli(object): self.print_usage() + def no_command(self): + print >> sys.stderr, _("No command given, see --help for details") + sys.exit(1) + def action_list_domains(self): ldap_con = ldap.initialize(self.conf.get('ldap', 'uri')) ldap_con.bind_s(self.conf.get('ldap', 'bind_dn'), self.conf.get('ldap', 'bind_pw')) -- cgit v1.1