optparse

how to distribute a ruby script via homebrew

余生长醉 提交于 2019-12-01 10:36:36
问题 How can I deploy a simple ruby script via homebrew? Here's what I tried Wrote formula in a GitHub repo named homebrew-foo # file https://github.com/foo/homebrew-foo/blob/master/foo.rb class Foo < Formula desc "A command line tool" url "https://github.com/foo/foo/archive/master.zip" version "5.0.1" def install bin.install "foo" lib.install Dir["lib/*"] end end The other repository contains the ruby script. These are the files ./foo ./lib/libfile1.rb here's what the script does #!/usr/bin/env

Python argparse argument with quotes

我与影子孤独终老i 提交于 2019-12-01 04:16:47
Is there any way I can tell argparse to not eat quotation marks? For example, When I give an argument with quotes, argparse only takes what's inside of the quotes as the argument. I want to capture the quotation marks as well (without having to escape them on the command line.) pbsnodes -x | xmlparse -t "interactive-00" produces interactive-00 I want "interactive-00" wim I think it is the shell that eats them, so python will actually never see them. Escaping them on the command line may be your only option. If it's the \"backslash\" style escaping you don't like for some reason, then this way

Disable unique prefix matches for argparse and optparse

你。 提交于 2019-12-01 02:56:25
When I use Python's argparse or optparse command line argument parser, any unique prefix of an argument is considered valid, e.g. $ ./buildall.py --help usage: buildall.py [-h] [-f] Build all repositories optional arguments: -h, --help show this help message and exit -f, --force Build dirty repositories works with --help , --hel , --he for the help option as well as --forc and --fo for the force option. Can this behavior be turned off somehow? I want to get an error message for incomplete arguments. The ability to disable abbreviated long options was only added in Python 3.5. From the argparse

Parsing command-line arguments as wildcards

非 Y 不嫁゛ 提交于 2019-11-30 19:34:27
问题 I wrote a simple script that writes all given arguments to a single text file, separated by newline. I'd like to pass a list of files to it using OptionParser. I would like to add a couple of files using wildcards like /dir/* . I tried this: opts = OptionParser.new opts.on('-a', '--add FILE') do |s| puts "DEBUG: before #{s}" @options.add = s puts "DEBUG: after #{@options.add}" end ... def process_arguments @lines_to_add = Dir.glob @options.add end Put when I add files like this: ./script.rb

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:

Python argparse ignore unrecognised arguments

耗尽温柔 提交于 2019-11-27 03:36:39
Optparse, the old version just ignores all unrecognised arguments and carries on. In most situations, this isn't ideal and was changed in argparse. But there are a few situations where you want to ignore any unrecognised arguments and parse the ones you've specified. For example: parser = argparse.ArgumentParser() parser.add_argument('--foo', dest="foo") parser.parse_args() $python myscript.py --foo 1 --bar 2 error: unrecognized arguments: --bar Is there anyway to overwrite this? Replace args = parser.parse_args() with args, unknown = parser.parse_known_args() For example, import argparse

How can I get optparse's OptionParser to ignore invalid options?

岁酱吖の 提交于 2019-11-27 02:33:52
问题 In python's OptionParser , how can I instruct it to ignore undefined options supplied to method parse_args ? e.g. I've only defined option --foo for my OptionParser instance, but I call parse_args with list [ '--foo', '--bar' ] EDIT: I don't care if it filters them out of the original list. I just want undefined options ignored. The reason I'm doing this is because I'm using SCons' AddOption interface to add custom build options. However, some of those options guide the declaration of the

Why use argparse rather than optparse?

南笙酒味 提交于 2019-11-26 15:37:27
I noticed that the Python 2.7 documentation includes yet another command-line parsing module. In addition to getopt and optparse we now have argparse . Why has yet another command-line parsing module been created? Why should I use it instead of optparse ? Are there new features that I should know about? Nicholas Knight As of python 2.7 , optparse is deprecated, and will hopefully go away in the future. argparse is better for all the reasons listed on its original page ( https://code.google.com/archive/p/argparse/ ): handling positional arguments supporting sub-commands allowing alternative

Why use argparse rather than optparse?

依然范特西╮ 提交于 2019-11-26 04:32:02
问题 I noticed that the Python 2.7 documentation includes yet another command-line parsing module. In addition to getopt and optparse we now have argparse . Why has yet another command-line parsing module been created? Why should I use it instead of optparse ? Are there new features that I should know about? 回答1: As of python 2.7 , optparse is deprecated, and will hopefully go away in the future. argparse is better for all the reasons listed on its original page (https://code.google.com/archive/p