summaryrefslogtreecommitdiffstats
path: root/ipalib/cli.py
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2009-06-09 15:24:23 -0400
committerRob Crittenden <rcritten@redhat.com>2009-07-10 16:44:54 -0400
commitfe84ffd0f1dfbdea158a07f177a174f41b803723 (patch)
tree7ff47956feaef673f7f0a98104fd4a7110a0bc7e /ipalib/cli.py
parent0e29dd7226119e69f3bf123395251140ad4260ca (diff)
downloadfreeipa-fe84ffd0f1dfbdea158a07f177a174f41b803723.tar.gz
freeipa-fe84ffd0f1dfbdea158a07f177a174f41b803723.tar.xz
freeipa-fe84ffd0f1dfbdea158a07f177a174f41b803723.zip
Add a return value to exceptions.
Returning the exception value doesn't work because a shell return value is in the range of 0-255. The default return value is 1 which means "something went wrong." The only specific return value implemented so far is 2 which is "not found".
Diffstat (limited to 'ipalib/cli.py')
-rw-r--r--ipalib/cli.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index df0cd37ca..1a1673e41 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -36,7 +36,7 @@ import frontend
import backend
import plugable
import util
-from errors import PublicError, CommandError, HelpError, InternalError, NoSuchNamespaceError, ValidationError
+from errors import PublicError, CommandError, HelpError, InternalError, NoSuchNamespaceError, ValidationError, NotFound
from constants import CLI_TAB
from parameters import Password, Bytes
from request import ugettext as _
@@ -440,6 +440,9 @@ class textui(backend.Backend):
return -1
counter = len(entries)
+ if counter == 0:
+ raise NotFound(reason="No matching entries found")
+
i = 1
for e in entries:
# There is no guarantee that all attrs are in any given
@@ -690,7 +693,11 @@ class cli(backend.Executioner):
if param.password and param.name in kw:
del kw[param.name]
(args, options) = cmd.params_2_args_options(**kw)
- cmd.output_for_cli(self.api.Backend.textui, result, *args, **options)
+ rv = cmd.output_for_cli(self.api.Backend.textui, result, *args, **options)
+ if rv:
+ return rv
+ else:
+ return 0
finally:
self.destroy_context()
@@ -799,7 +806,7 @@ def run(api):
api.register(klass)
api.load_plugins()
api.finalize()
- api.Backend.cli.run(argv)
+ sys.exit(api.Backend.cli.run(argv))
except KeyboardInterrupt:
print ''
api.log.info('operation aborted')
@@ -811,4 +818,4 @@ def run(api):
if error is not None:
assert isinstance(error, PublicError)
api.log.error(error.strerror)
- sys.exit(error.errno)
+ sys.exit(error.rval)