This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Option parsing in gdb python


Paul Koning wrote:
> Since argparse is the successor to optparse and is easier to use and more extensible, would you consider doing this in argparse instead?

I can do this (and did; read on, Dear Reader).  Does gdb python have a position on python 2.6 support?  If so, and if gdb accepts this parser, we should provide both and wrap the imports in try blocks
	try:
	   import argparse
	   …
	except ImportError:
	   pass
etc.

OK, using argparse here goes:

           parser = GdbArgumentParser("show image")
           parser.add_argument("-a", "--all", action="store_true", help="Display the whole image/mask")
           parser.add_argument("image", help="Expression giving image to show")
           parser.add_argument("width", help="Width of patch to print", default=1, nargs="?")

           opts =  parser.parse_args(args)

					R


import argparse

class GdbArgumentParser(argparse.ArgumentParser):
    def parse_args(self, args=None, namespace=None):
        if args:
            args = gdb.string_to_argv(args)
        return argparse.ArgumentParser.parse_args(self, args, namespace)
        
    def exit(self, status=0, msg=None):
        raise gdb.GdbError(msg)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]