optionparser

Parsing empty options in Python

梦想与她 提交于 2019-12-04 09:41:22
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 requires an argument" Being that there are over 200 points of data, it's not like I can write separate

How to use variable arguments with ruby's OptionParser

主宰稳场 提交于 2019-12-03 13:06:57
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 appreciated. OPTS = {} op = OptionParser.new do |x| x.banner = 'cat <options> <file>' x.separator '' x.on("

Ruby OptionParser empty switch “-” behavior

安稳与你 提交于 2019-12-01 01:43:53
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 requires two mandatory switches, but it accepts one switch without complaining! e.g. program.ruby -f foo -b bar is the valid input and both switches are :REQUIRED. But providing only one switch passes without problem and this is not the desired behavior. For the first case I've done this: opts.on('-', /\A-\Z/) do $stderr.print "Invalid empty switch"

Ruby OptionParser empty switch “-” behavior

早过忘川 提交于 2019-11-30 21:08:10
问题 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 requires two mandatory switches, but it accepts one switch without complaining! e.g. program.ruby -f foo -b bar is the valid input and both switches are :REQUIRED. But providing only one switch passes without problem and this is not the desired

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

夙愿已清 提交于 2019-11-28 16:49:17
I'm writing a script and I want to require a --host switch with value, 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. I am assuming you are using optparse here, although the same technique will work for other option parsing libraries. The simplest method is probably to parse the parameters using your chosen option parsing library and then raise an OptionParser::MissingArgument Exception if the value of host is nil. The following

understanding OptionParser

五迷三道 提交于 2019-11-28 03:07:10
问题 I was trying out optparse and this is my initial script. #!/usr/bin/env python import os, sys from optparse import OptionParser parser = OptionParser() usage = "usage: %prog [options] arg1 arg2" parser.add_option("-d", "--dir", type="string", help="List of directory", dest="inDir", default=".") parser.add_option("-m", "--month", type="int", help="Numeric value of the month", dest="mon") options, arguments = parser.parse_args() if options.inDir: print os.listdir(options.inDir) if options.mon:

Is OptionParser in conflict with sphinx?

一曲冷凌霜 提交于 2019-11-27 15:32:07
I'm trying to write a documentation for my project in sphinx and whenever sphinx encounters OptionParser in my module it gives me: sphinx-build: error: no such option: -b I thought that it's impossible, so I wrote a simple module to check this: from optparse import OptionParser """some comment here""" parser = OptionParser(conflict_handler='resolve') parser.add_option('', '--force', action='store_true', dest='force', default=False, help='gqdel will skip asking questions, and delete them all.'); parser.add_option('', '--verbose', action='store_true', dest='verbose', default=False, help='Report

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

本小妞迷上赌 提交于 2019-11-27 09:58:12
问题 I'm writing a script and I want to require a --host switch with value, 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. 回答1: I am assuming you are using optparse here, although the same technique will work for other option parsing libraries. The simplest method is probably to parse the parameters using your chosen option parsing

Is OptionParser in conflict with sphinx?

和自甴很熟 提交于 2019-11-26 18:31:34
问题 I'm trying to write a documentation for my project in sphinx and whenever sphinx encounters OptionParser in my module it gives me: sphinx-build: error: no such option: -b I thought that it's impossible, so I wrote a simple module to check this: from optparse import OptionParser """some comment here""" parser = OptionParser(conflict_handler='resolve') parser.add_option('', '--force', action='store_true', dest='force', default=False, help='gqdel will skip asking questions, and delete them all.'