Questions tagged [optionparser]
93 questions
2
votes
1 answer
Ruby OptionParser: 2 options, 1 argument
I am attempting to use OptionParser to read in multiple options and have them all act on a single filename. Ex: myprogram.rb -a -b file.txt How can I make 2 options share a mandatory argument while also allowing things like -h to run without…

AnthonyW
- 1,910
- 5
- 25
- 46
2
votes
0 answers
How should I solve the conflict of OptionParser and sphinx-build in a large project?
I have a large Python project with many external libraries I don't want to touch and I want to generate the documentation with sphinx. My problem is, whenever I execute "make html", I get this error:
...
usage: sphinx-build [global_opts] cmd1…

alfa
- 3,058
- 3
- 25
- 36
2
votes
0 answers
How to handle a single "-" (dash) in OptionParser?
Possible Duplicate:
Ruby OptionParser empty switch “-” behavior
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.
The program requires…

ismail
- 266
- 2
- 12
1
vote
1 answer
Nil parameter in OptionParser
i try to set my script to run something like this
ruby Script.rb --ip "192.168.3.206"
But if there is no ip parameter then it use default "192.168.1.1
I try this code, but it's always return nil as ip
options = {}
OptionParser.new do |opts|
…

ShockwaveNN
- 2,227
- 2
- 29
- 56
1
vote
0 answers
Why is the input string read by OptParser?
I am currently creating a launcher (launcher.py) in Python 2.7 which can be used from GUI and terminal input. The launcher combines already eisting Software, that has its own GUI and its own terminal mode.
I added an OptionParser (option.py) to…

pummeluff25
- 11
- 1
1
vote
2 answers
Unable to use OptionParser and rspec
I have a simple watir (web-driver) script which goes to google. But, I want to use option parser to set an argument in the cmd to select a browser. Below is my script:
require 'optparse'
require 'commandline/optionparser'
include CommandLine
require…

Sun
- 2,658
- 6
- 28
- 33
1
vote
1 answer
Where is the documentation for Ruby OptionParser's parse! method?
I have been unable to locate any documentation for parse!, a very commonly used instance method for the OptionParser class from Ruby's standard distribution.
I have seen parse! used in the examples at the top of the documentation for the OptionParse…

Ryan Tate
- 1,553
- 2
- 14
- 21
1
vote
2 answers
In Ruby, how can I escape a comma in an argument parameter with OptionParser?
Given the following code:
options = {}
optparse = OptionParser.new do |opts|
opts.on('-t', '--thing [THING1,THING2]', Array, 'Set THING1, THING2') do |t|
options[:things] = t
end
end
If THING1 has a comma in it, how can I prevent…

Scott Smith
- 111
- 3
1
vote
1 answer
Is there any way to take inputs for a option created using parser.add_option, and not take any input for the same option?
Now when I type " python openweather.py --api=key --city=London --temp=fahrenheit " in command prompt, I get the desired output of temperature in fahrenheit or even if celcius is entered (" --temp=celcius ") I get the desired output of temperature…

Junaid
- 63
- 1
- 9
1
vote
1 answer
Is it possible to send an 'OptionParser' object as input arguement to run main of imported python module?
There are two python scripts, 'script1.py' and 'script2.py'.
'script1.py' uses OptionParser to parse command line arguments.
The contents of 'script1.py' look something like this
from optparse import OptionParser
def main():
parser =…

shy_am
- 13
- 4
1
vote
1 answer
Crystal lang takes option parameters from OptionParser when it shouldn't
I started paying around with Crystal lang, I want to use OptionParser to show a help text, however -h will be interpred by Crystal instead of OptionParser
I am using the example from https://crystal-lang.org/api/0.18.7/OptionParser.html
and calling…

Snake Sanders
- 2,641
- 2
- 31
- 42
1
vote
1 answer
Set and require default Python script OptionParser
The following "parser.add_option" statements work but if the script is run without an option/arg it will not complain. If an option/argument are not specified I would like it to display help (-h / --help) as default.
usage = "usage: %prog [options]…

Astron
- 1,211
- 5
- 20
- 42
1
vote
1 answer
Option Parser does not match argument
I have a simple python (v2.7) script (test.py)
#!/usr/bin/python
import sys
from optparse import OptionParser
def main():
parser = OptionParser()
parser.add_option("--files", dest="files",
metavar="FILES",…

dimitris lepipas
- 263
- 3
- 15
1
vote
0 answers
OptionParser, requiring subparameters
I'm trying to figure out how to define subparameters for one of my parameters. This is what I have that is NOT working:
require 'optparse'
options = {}
OptionParser.new do |parser|
parser.on("-r", "--require LIBRARY", "Require the LIBRARY before…

ed_is_my_name
- 601
- 3
- 9
- 24
1
vote
1 answer
How to use different options for every positional argument with OptionParser
I want to make a script invoked with this syntax:
script.rb [common-options] arg1 [arg1-options] [arg2 [arg2-options] …]
For example:
script.rb --verbose --dry-run a1 --outfile c1 a2 --reprocess --outfile c2 a3 a4 --outfile b42
Returning something…

Envek
- 4,426
- 3
- 34
- 42