optionparser

Unable to use OptionParser and rspec

和自甴很熟 提交于 2021-01-28 05:08:13
问题 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 'watir-webdriver' describe 'Test google website' do before :all do options = {} opts = OptionParser.new do |opts| opts.on("--browser N", "Browser to execute test scripts") do |n| options[:browser] = n $b = n.to_s end end opts.parse! ARGV p options

[转]optionParser模块的使用方法

陌路散爱 提交于 2020-03-19 15:00:40
3 月,跳不动了?>>> Python 有两个内建的模块用于处理命令行参数: 一个是 getopt,《Deep in python》一书中也有提到,只能简单处理 命令行参数; 另一个是 optparse,它功能强大,而且易于使用,可以方便地生成标准的、符合Unix/Posix 规范的命令行说明。 示例 from optparse import OptionParser parser = OptionParser() parser.add_option("-p", "--pdbk", action="store_true", dest="pdcl", default=False, help="write pdbk data to oracle db") parser.add_option("-z", "--zdbk", action="store_true", dest="zdcl", default=False, help="write zdbk data to oracle db") (options, args) = parser.parse_args() if options.pdcl==True: print 'pdcl is true' if options.zdcl==True: print 'zdcl is true' add_option用来加入选项

How should I solve the conflict of OptionParser and sphinx-build in a large project?

蓝咒 提交于 2020-01-04 06:51:58
问题 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 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: sphinx-build --help [cmd1 cmd2 ...] or: sphinx-build --help-commands or: sphinx-build cmd --help error: option -b not recognized make: *** [html] Fehler 1 I already figured out that this problem occurs when there is

How should I solve the conflict of OptionParser and sphinx-build in a large project?

喜夏-厌秋 提交于 2020-01-04 06:51:21
问题 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 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: sphinx-build --help [cmd1 cmd2 ...] or: sphinx-build --help-commands or: sphinx-build cmd --help error: option -b not recognized make: *** [html] Fehler 1 I already figured out that this problem occurs when there is

boost::program_options config file option with multiple tokens

醉酒当歌 提交于 2019-12-20 17:56:17
问题 I can not seem to be able to read from config file multitoken options like I can from command line. What is the syntax for the config file? This is how the option description is added: //parser.cpp - - - po::options_description* generic; generic=new po::options_description("Generic options"); generic->add_options() ("coordinate",po::value<std::vector<double> >()->multitoken(),"Coordinates (x,y)"); After which I parse command and config-files. On command line '--coordinate 1 2' works. However,

Using ruby's OptionParser to parse sub-commands

人走茶凉 提交于 2019-12-20 08:41:15
问题 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 to learn the library better. Any tips? 回答1: Figured it out. I need to use OptionParser#order! . It will parse all the options from the start of ARGV until it finds

Set a default choice for optionparser when the option is given

一个人想着一个人 提交于 2019-12-11 06:24:54
问题 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 the default, not only when --list-something was given. from optparse import OptionParser, OptionGroup parser = OptionParser() options = OptionGroup(parser, "options") options.add_option("--list-something", type="choice", choices=["simple",

How to use variable arguments with ruby's OptionParser

自古美人都是妖i 提交于 2019-12-09 11:22:53
问题 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 question is how would I write the command line options parsing part of cat in ruby using OptionParser cat [OPTION]... [FILE]... Hope that makes sense, any help is

OptionParser python module - multiple entries of same variable?

早过忘川 提交于 2019-12-08 21:26:20
问题 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 gather stats [default: localhost]") ... my GOAL is to be able to do something like #test.py -s server1 -s server2 and it would append both of those values within the options

Parsing empty options in Python

∥☆過路亽.° 提交于 2019-12-06 06:04:54
问题 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 application builds the string to send to the script, some of the arguments are blank and python's OptionParser errors out with "error: --someargument option