Questions tagged [optionparser]
93 questions
0
votes
1 answer
How can I use OptionParser to print to the command line?
I'd like to use option parser to print the result of a computation to the command line. So far, I have
parser = OptionParser()
parser.add_option('-s','--some', help = "Print some of the Suspects")
parser.add_option('-a','--all',help = "Print all…

user3600497
- 1,621
- 1
- 18
- 22
0
votes
2 answers
Python OptionParser to allow multiple arguments for choice type option
I have an option in OptionParser as seen below:
foo_choices = ['foo', 'bar', 'mac', 'win']
parser.add_option('-t', '--test',
type='choice',
action='store',
dest='test',
…

Shark
- 2,322
- 5
- 31
- 44
0
votes
2 answers
Display list of option choices in help text automatically in OptionParser
I have an option in OptionParser that takes in a list of choices.
#!/usr/bin/python
from optparse import OptionParser
def main():
parser = OptionParser(usage="Usage: foo")
parser.add_option('-e', '--env',
…

Shark
- 2,322
- 5
- 31
- 44
0
votes
1 answer
passing blocks to be used in OptionParser on method
I want to wrap OptionParser in another function that defines some defaults, but allows
me to overwrite the banner, add separators, and add new options. I am having a hard time passing the relevant information to the on method.
Any advice on how to…

mr paul
- 31
- 3
0
votes
1 answer
Splitting ARGV into two file lists
I am using Ruby OptionParser but can not figure out how to get non-option arguments as two lists.
myscript --option-one --option-two file1 file2 -- file10 file11
Is there a way to get from OptionParser two lists of files separately?
[file1,…

Nik O'Lai
- 3,586
- 1
- 15
- 17
0
votes
1 answer
Ruby OptionParser throwing ArgumentError
this is my first time using OptionParser and i'm getting this error:
/Users/jay/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mechanize-> 2.7.3/lib/mechanize/http/agent.rb:651:in resolve': absolute URL needed (not -v) (ArgumentError)from…

TuxedoTomson
- 483
- 4
- 16
0
votes
1 answer
How to fit parser in my python script
Normally, if I have to perform an overlap between multiple files, I just execute:
python -c 'import sys;print "".join(sorted(set.intersection(*[set(open(a).readlines()) for a in sys.argv[1:]])))' File1 File2 File3 File4 ....
But if I have to get…

Angelo
- 4,829
- 7
- 35
- 56
0
votes
1 answer
Adding an element to a bash array
I have been trying to write a very basic generic bash option parser for one of my projects. The idea is as follows:
I feed a list of command-line arguments, some of them are options
I want to extract the options into a separate array
I will end up…

Robert Audi
- 8,019
- 9
- 45
- 67
0
votes
2 answers
optparse in ruby test to set target server for webdriver
I need to have my webdriver tests hit multiple servers. My solution was to pass in a command line parameter but when run the code below using
ruby webdriver/e2e/*.rb -s=localhost
or
ruby webdriver/e2e/*.rb --server=localhost
but I get the…

jgreenberg
- 478
- 1
- 4
- 17
0
votes
1 answer
Suppress short arguments with OptionParser
I have a Ruby app with a relatively broad set of command-line arguments. I would like to suppress "short" variants for a number of options so that they can only be used in the long ("double dash") form.
Can I somehow suppress short dash variants for…

Julik
- 7,676
- 2
- 34
- 48
0
votes
2 answers
why won't Ruby OptionParser read all of my arguments?
This is my code:
#!/usr/bin/env ruby
# OptionParser
require 'optparse'
options = {}
optparse = OptionParser.new do|opts|
opts.banner = '...'
# This option inputs ...
options[:Lap1] = []
opts.on('-1', '--Lap1…

Blaid
- 1
- 1
0
votes
2 answers
OptionParser to parse arguments form file instead of command line
I am using Ruby to execute a code that takes command line arguments.
now i trying to use the same program with differnt options so i am putting the options in a file and i want the program to read each line interpret the options and execute the…

user2300908
- 165
- 1
- 1
- 12
0
votes
0 answers
Ruby OptionParser: process all not specified options
I am trying to a custom processor of all options not specified in OptionParser.
But parse raises exception when first unknown option is found.
Is it possible to get all unprocessed parameters and process them manually?

Bogdan Gusiev
- 8,027
- 16
- 61
- 81
0
votes
1 answer
Ruby OptionParser throwing MissingArgument
Let me preface this with two things.
1) I've searched Stack Overflow and Google for this answer.
2) Today is the first day I've ever tried to mess with Ruby.
Alright cool. So what I'm doing is trying to build a Ruby script that I can use to install…

Andrew Ellis
- 1,175
- 1
- 12
- 29
0
votes
2 answers
Ruby OptionParser empty switch "-" behavior
EDITED:
I've wrote code that uses OptionParser to handle command line input gracefully. I am facing two major hits.
Passing an empty switches '-' doesn't give an error. Of course some programs take that as valid, but mine shouldn't.
The program…

ismail
- 266
- 2
- 12