Better messages and return codes in applications

Use stderr and return codes >0 when it makes sense.
Loose return code conventions:
* 1 for generic errors
* 2 for user input errors
* 3 for remote errors (not found, etc.)
* 4 for not implemented
This commit is contained in:
Laurent Bachelier 2011-05-03 01:02:00 +02:00
commit 8075d538f0
18 changed files with 168 additions and 149 deletions

View file

@ -53,16 +53,16 @@ class Pastoob(ReplApplication):
print args
if not _id:
print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('get', short=True)
return 1
return 2
try:
paste = self.get_object(_id, 'get_paste', ['contents'])
except PasteNotFound:
print >>sys.stderr, 'Paste not found: %s' % _id
return 2
return 3
if not paste:
print >>sys.stderr, 'Unable to handle paste: %s' % _id
return 3
return 1
output = codecs.getwriter(sys.stdout.encoding)(sys.stdout)
output.write(paste.contents)
# add a newline unless we are writing