optionparser

Parsing empty options in Python

I have an application that allows you to send event data to a custom script. You simply lay out the command line arguments and assign what event data goes with what argument. The problem is that there is no real flexibility here. Every option you map out is going to be used, but not every option will necessarily have data. So when the ap...

How do you specify a required switch (not argument) with Ruby OptionParser?

Say I'm writing a script and I want to require a --host switch (with value of course) but if the --host switch isn't specified I want the option parsing to fail. I can't seem to figure out how to do that. The docs seem to only specify how to make the argument value mandatory, not the switch itself. ...

How to use variable arguments with ruby's OptionParser

I don't know ruby very well, but I'm trying to add some functionality to this script a co-worker wrote. Basically right now it takes a few flags and standard in as input, and it uses OptionParser to parse the flags. I want to use OptionParser to parse a selection of command line arguments similar to those of cat. So I guess my questio...

How do I handle a missing mandatory argument in Ruby OptionParser?

In OptionParser I can make an option mandatory, but if I leave out that value it will take the name of any following option as the value, screwing up the rest of the command line parsing. Here is a test case that echoes the values of the options: $ ./test_case.rb --input foo --output bar output bar input foo Now leave out the value...

Using ruby's OptionParser to parse sub-commands

I'd like to be able to use ruby's OptionParser to parse sub-commands of the form COMMAND [GLOBAL FLAGS] [SUB-COMMAND [SUB-COMMAND FLAGS]] like: git branch -a gem list foo I know I could switch to a different option parser library (like Trollop), but I'm interested in learning how to do this from within OptionParser, since I'd like ...

OptionParser python module - multiple entries of same variable?

I'm writing a little python script to get stats from several servers or a single server, and I'm using OptionParser to parse the command line input. #!/usr/bin/python import sys from optparse import OptionParser ... parser.add_option("-s", "--server", dest="server", metavar="SERVER", type="string", help="server(s) to...

Application with both console and gui mode

Hi, I have a python console app. Like most python console apps it uses the OptionParser module to take arguments. I've now developed a GUI for my app using wxPython and i'd like to integrate the two. I'd like my app to be run both from the console and from the OS's UI. When it is invoked from the console it runs as a console app and whe...

Can I use Ruby's OptionParser to accept an arbitrary argument pattern?

Let's say that I have a simple Ruby app where I want the first argument (if any) to specify the environment: TEST, DEVELOPMENT or PRODUCTION (with DEVELOPMENT being the default if no argument is given). For instance, ruby myapp.rb test would run it in TEST mode. Also, shorthands should be accepted, so that for instance ruby myapp.rb ...

Ruby: OptionParser: String Arg & Hash Assignment

Using OptionParser for string argument input and hash assignment. What is the best way to read-in multiple variables for a single argument? How do I then assign those to a hash to reference? Here is what I have so far: large_skus = Hash.new small_skus = Hash.new OptionParser.new do |opts| opts.on("-b", "--brands bName1,bName2,bName...