[IPython-dev] Magics that multiplex
Wed Jul 25 12:51:02 CDT 2012
On Wed, Jul 25, 2012 at 10:40 AM, David Quigley <firstname.lastname@example.org>wrote:
> I'm working on implementing a magic that multiplexes its behavior based
> on the first token of the line after the magic. An example of a tool
> which would do something like this is semanage or ip which based on the
> second token ( port, login, fcontext, etc...) Behaves differently. I'm
> doing it this way because these commands really belong to the same
> component and are generic enough in name that they will appear again.
> For example I want to have server start, server stop, server status be
> magic commands. Is there functionality to do this already in the magics
> subsystem? I looked at the parse_options code in Magics and it doesn't
> seem to handle that kind of usecase (although I'd be glad to be proven
> wrong). Alternatively I've used argparse in the past with subparsers to
> do just that. argparse.ArgumentParser can have subparsers added to it to
> then process arguments based on the second token in the line. Is there
> anything incorrect about using an option parser that isn't
There's definitely nothing wrong with using your own parsing if you have a
reason to - the magic API is that you get a line (or line and cell), and
you do something with that. No further restrictions.
> Is there an already existing way to do this? I'm
> using the rel-0.13 tag from git but can use -dev if necessary.
I don't *think* we have any library code to make subcommands easier, so I
think you are probably on the right path using ArgumentParser with
> IPython-dev mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-dev