Questions tagged [optionparser]
93 questions
1
vote
2 answers
python OptionParser.has_option error
I have these below lines in my program
parser = OptionParser()
parser.add_option("-t","--TIMEOUT", dest="timeout", type="int", help="timeout in seconds")
if parser.has_option("-t") and options.timeout<=0:
print "Timeout if specified must be…

yalkris
- 2,596
- 5
- 31
- 51
1
vote
2 answers
Set a default choice for optionparser when the option is given
I have a python option parsers that parses an optional --list-something option.
I also want the --list-something option to have an optional argument (an option)
Using the argument default="simple" does not work here, otherwise simple will always
be…

Jens Timmerman
- 9,316
- 1
- 42
- 48
1
vote
3 answers
Defining a variable with optparse in Python
I am curious how to set a variable using optparse. I run the program as such;
programname.py -d c:\users\\etc\etc\etc
I want to be able to use -d C:\Users\\etc\etc to populate a variable called, "path", which I use later in the program. Can this be…

mrwh1t3
- 349
- 1
- 4
- 13
0
votes
0 answers
How can I implement git like cli with python click with commands subcommands and options.?
Want to achieve like this using click framework in python:
Each options have aliases and suboptions have short form and long form(-n, --dry-run)
git --help
work on the current change (see also: git help everyday)
add Add file…

tony
- 71
- 2
0
votes
1 answer
Perform checks that include multiple options
I have
type Month = Int
parseMonths :: OP.Parser (Month, Month)
parseMonths =
liftA2 (,)
(OP.option
(OP.eitherReader $
parseNumber "month" (\n -> 1<=n && n<=12) "month")
(OP.metavar "MONTH" <>
…

Lemming
- 577
- 6
- 16
0
votes
1 answer
C: getopt_long() always returns invalid option
I'm trying to add a new option to an already working C program using getopt_long. The option I want to add is -S but every time I try to run the code I get:
./HidCom: invalid option --'S'
I simply add a new element to long_options vector concerning…

Vincenzo Cristiano
- 77
- 6
0
votes
1 answer
I have three flags in OptionParser but it only gives access to two of them
I am building a CLI gem with Ruby and I'm using OptionParser to add flags with arguments. Whenever one flag is called with an argument a function get's called.
I have three flags. My problem is, when I run the -h command to see the options(flags)…

problems
- 95
- 1
- 8
0
votes
1 answer
python3.7 optionparser input option with asterisk(*) becomes a file in the folder
Env:
python3.7
OptionParser with a option [ add_option('-t', '--target', action='append', dest='targets') ]
OS: CentOS7.6
Problem:
So I am using this option to input a list of targets, and with this command line:
parser -t logs* -t test
…

Snart
- 54
- 6
0
votes
2 answers
How to execute python class modules along with pytest and option parser?
main
|--> src
|--> custom_calculation.py
|--> test_custom_calculation.py
custom_calculation.py
def calc_total(a,b):
return a+b
def calc_multiply(a,b):
return a*b
test_custom_calculation.py
import…

StackGuru
- 471
- 1
- 9
- 25
0
votes
1 answer
Using OptionParser with a 'Default' list of opts
I'm attempting to create a default opts list using OptionParser that can be used in separate files that share the same opts. Ex:
File 1:
default = OptionParser.new do |opts|
opts.banner = "This banner is shared by multiple files"
opts.on("-d",…

Brandon R
- 3
- 2
0
votes
1 answer
How to pattern match on Scala Scopt optional arguments
I have a simple Scops parser that looks like
val parser: scopt.OptionParser[Config] = new scopt.OptionParser[Config]("my-app") {
head("scopt", "3.x")
(...)
opt[String]('q', "query")
.text("The query.")
.action { (value, conf) =>…

Vassilis Moustakas
- 573
- 1
- 7
- 17
0
votes
2 answers
Forward a shell command using python
So to be more precise, what I am trying to do is :
read a full shell command as argument of my python script like : python myPythonScript.py ls -Fl
Call that command within my python script when I'd like to (Make some loops on some folders and…

Othman Benchekroun
- 1,998
- 2
- 17
- 36
0
votes
1 answer
How to update multi-level dictionary present in another python file?
example.py
This is a python script, which has a multi-level dictionary.
test_dict = {'path': '/home/user/user_name',
'device1': {'IP': '10.10.10.10',
'password': 'pwd1',
'username': 'user1',
'name':'USER_DEFINED'},
…

Jackie
- 129
- 17
0
votes
1 answer
Receive a shell command as an OptionParser string argument
I am using OptionParser(), and define the following:
parser.add_option("--cmd", dest="command", help="command to run")
However, if i provide a complex shell command, such as :
python shell.py --cmd "for i in `seq 1 10`; do xxx; done"
And…

sramij
- 4,775
- 5
- 33
- 55
0
votes
1 answer
parameters and switches in bash script
I need to modify one of my scripts. Until now it has two obligatory parameters which point out to version of update and database where this update is going to be applied
./script.sh version db_name
Now I want to add two new optional parameters, in…

user3863616
- 185
- 1
- 9
- 24