1. dgc
  2. awstools


dgc  committed c15c30f

allow subcommands to raise usage errors

The subcommand framework handles some general case usage errors, but
otherwise subcommands implementation functions must perform their own
error handling. Now they can do it simply by raising aws.UsageError.
The exception will bubble up to the framework which will announce the
error to the UI and deliver conventional usage information.

  • Participants
  • Parent commits e154338
  • Branches default

Comments (0)

Files changed (1)

File aws.py

View file
  • Ignore whitespace
 import os
 import ConfigParser
+class AWSError(Exception): pass
+class UsageError(AWSError): pass
 class awsuser(object):
 	userdir = os.path.expanduser(os.path.join('~', '.aws'))
 		if sub[3] is not None and len(args) > sub[3]:
 			error('too many arguments to %s' % sub[0])
 			return 2
-		return sub[1](sess, args)
+		try:
+			return sub[1](sess, args)
+		except UsageError, e:
+			error(sub[0] + ': ' + str(e))
+			return 2
 	error('unknown subcommand %s' % verb)