VMM/cli: Make sure that there is at least one argument. v0.7.x
authorPascal Volk <user@localhost.localdomain.org>
Mon, 03 Feb 2014 20:22:29 +0000
branchv0.7.x
changeset 713 74ee0a62039c
parent 712 6be7e9085e94
child 714 95252b15fffb
VMM/cli: Make sure that there is at least one argument.
VirtualMailManager/cli/main.py
VirtualMailManager/constants.py
vmm
--- a/VirtualMailManager/cli/main.py	Sun Feb 02 17:10:43 2014 +0000
+++ b/VirtualMailManager/cli/main.py	Mon Feb 03 20:22:29 2014 +0000
@@ -14,8 +14,8 @@
 from VirtualMailManager.config import BadOptionError, ConfigValueError
 from VirtualMailManager.cli import w_err
 from VirtualMailManager.cli.handler import CliHandler
-from VirtualMailManager.constants import EX_SUCCESS, EX_USER_INTERRUPT, \
-     INVALID_ARGUMENT
+from VirtualMailManager.constants import EX_MISSING_ARGS, EX_SUCCESS, \
+     EX_USER_INTERRUPT, INVALID_ARGUMENT
 from VirtualMailManager.cli.subcommands import RunContext, setup_parser
 
 
@@ -34,8 +34,12 @@
         return handler
 
 
-def run():
+def run(argv):
     parser = setup_parser()
+    if len(argv) < 2:
+        parser.print_usage()
+        parser.exit(status=EX_MISSING_ARGS,
+                   message=_('You must specify a subcommand at least.') + '\n')
     args = parser.parse_args()
     handler = _get_handler()
     run_ctx = RunContext(args, handler)
--- a/VirtualMailManager/constants.py	Sun Feb 02 17:10:43 2014 +0000
+++ b/VirtualMailManager/constants.py	Mon Feb 03 20:22:29 2014 +0000
@@ -32,6 +32,7 @@
 # exit codes
 
 EX_SUCCESS = 0
+EX_MISSING_ARGS = 1
 EX_USER_INTERRUPT = 3
 
 
--- a/vmm	Sun Feb 02 17:10:43 2014 +0000
+++ b/vmm	Mon Feb 03 20:22:29 2014 +0000
@@ -15,4 +15,4 @@
     # Otherwise just remove /usr/local/sbin from sys.path
     sys.path.remove(sys.path[0])
     from VirtualMailManager.cli.main import run
-    sys.exit(run())
+    sys.exit(run(sys.argv))