API CHANGE: replace print_version_and_exit with format_version

The --version option was previously subject to syntax validation of
other args when it shouldn't be.  This commit switches to a 'version'
arg type, but this comes at the cost of replacing the
print_version_and_exit function with a format_version function that
simply returns the version string.
This commit is contained in:
Garrett Holmstrom
2013-04-25 14:45:55 -07:00
parent 08ecbbc9fb
commit 5a5a885f87
2 changed files with 5 additions and 8 deletions

View File

@@ -161,8 +161,8 @@ class BaseCommand(object):
parser.add_argument('--debugger', action='store_true', dest='_debugger',
default=argparse.SUPPRESS,
help='launch interactive debugger on error')
parser.add_argument('--version', action='store_true', dest='_version',
default=argparse.SUPPRESS,
parser.add_argument('--version', action='version',
version=self.suite.format_version(),
help="show the program's version and exit")
if any('-h' in arg_obj.pargs for arg_obj in arg_objs
if isinstance(arg_obj, Arg)):
@@ -224,8 +224,6 @@ class BaseCommand(object):
if cli_args.pop('_debugger', False):
self.__debug = True
sys.excepthook = _debugger_except_hook
if cli_args.get('_version', False):
self.suite.print_version_and_exit()
# Everything goes in self.args. distribute_args() also puts them
# elsewhere later on in the process.
self.args.update(cli_args)

View File

@@ -13,9 +13,9 @@
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import platform
from requestbuilder import __version__
import requests
import sys
from . import __version__
class RequestBuilder(object):
@@ -27,9 +27,8 @@ class RequestBuilder(object):
self.__user_agent = None
@staticmethod
def print_version_and_exit():
print >> sys.stderr, 'requestbuilder', __version__, '(Prelude)'
sys.exit()
def format_version():
return 'requestbuilder {0} (Prelude)'.format(__version__)
@staticmethod
def list_config_files():