Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Robert Lupton the Good <rhl@astro.princeton.edu>
To: gdb@sourceware.org
Subject: RE: Option parsing in gdb python
Date: Mon, 24 Oct 2011 21:28:00 -0000	[thread overview]
Message-ID: <1C69408D-CEF9-4B86-A2E2-4A7547F069D9@astro.princeton.edu> (raw)
In-Reply-To: <1319403653.11425.ezmlm@sourceware.org>

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)


       reply	other threads:[~2011-10-24 21:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1319403653.11425.ezmlm@sourceware.org>
2011-10-24 21:28 ` Robert Lupton the Good [this message]
2011-10-24 21:35   ` Joel Brobecker
2011-10-25  2:58     ` Robert Lupton the Good
2011-10-27 17:01     ` Tom Tromey
2011-10-27 19:32   ` Tom Tromey
2011-10-22  1:22 Robert Lupton the Good
2011-10-23 21:00 ` Paul_Koning

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1C69408D-CEF9-4B86-A2E2-4A7547F069D9@astro.princeton.edu \
    --to=rhl@astro.princeton.edu \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox