{ "info": { "author": "Lain Supe (lainproliant)", "author_email": "lainproliant@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": "optspec - A wrapper around getopt\n=================================\n\noptspec is a wrapper around getopt that provides option parsing, mapping, counting,\nand enforcement of required parameters. I wrote this because I enjoy the\nsimplicity of getopt.getopt(), but dislike the duplication involved in\ninterpreting its results into variables or settings.\n\nChange Log\n==========\nMay 1 2016 (v0.5): Added ability to pass arbitrary parameters into SubcommandMap.invoke().\nMay 1 2016 (v0.6): Fixed missing 'return self' in Options.inherit().\n\nOption Specifications: The `Option.opt()` Function\n==================================================\nThe `opt()` function accepts a series of option forms, and keyword arguments\nidentifying the option's behavior.\n\nThe option forms are either shortopts or longopts based on their length:\nsingle-char forms are shortopts and multi character forms are longopts\n(sorry, no single-char longopts). Every form in the specification (optspec)\nwill map to the same key in the resulting option map (optmap). This key,\naka `name`, is determined by the first longopt specified, or the first shortopt\nspecified if no longopts are specified, and can also explicitly be specified\nwith the `name` keyword argument.\n\n- `name`: Explicitly specifies the option map value key, which is normally\n implied from the option forms. This can also be used to map options with\n different meanings to the same value key, as per the `-v` and `-q` options\n in the example below.\n- `param = True`: Indicates that the option takes a parameter. If the option is\n not specified, the value in the resulting optmap will be determined based on the\n following rules:\n - If `default` was specified, that value is provided.\n - If `multi = True`, the result is an empty list to indicate that no parameters were provided for a multi parameter option.\n - Otherwise, `None` is provided as the value for the optmap key.\n- `required = True`: Indicates that the option is required, and implies\n `param = True`. If the option is not specified in `sys.argv` or the provided\n `argv`, the `parse()` function will raise an exception.\n- `additive = True`: Indicates that the option is additive. If the option takes\n a parameter, then each time the parameter is provided, it is added to the\n previous value instead of replacing it using the `+` operator. If the option\n takes no parameters, then `increment` is added to `default` (or `0` if `default`\n was not provided).\n- `multi = True`: Indicates that the option can take multiple parameters by being\n specified multiple times. Each time the option is specified the resulting value\n is added to a list and this list is provided as the value for the optmap key.\n Note that an option may not be `additive` and `multi`, if `multi` is specified\n all rules for `additive` are ignored.\n- `default`: Specifies a default value to use for an option with parameters, and\n also indicates the starting value for additive options. If specified for an\n option that is `multi`, this had ought to be a list or collection of some sort.\n- `parser`: Provide a function that is used to parse parameters to options from\n strings. This is the identify function `lambda a: a` by default. Some common\n useful values for this include `int` and `float`.\n- `increment`: Specifies the value to be added to `default` for `additive` options\n where `param = False`. This defaults to `1`.\n\nExample Usage\n-------------\n\nTo use optspec, create an Option object, then specify a series of options using\nthe `opt()` function successively. Then, you may call the `parse()` function with\nno parameters to parse from `sys.argv` implicitly, or provide your own `argv`\nas a parameter.::\n\n from optspec import Options\n\n optmap, args = ( Options()\n .opt('s', 'safe')\n .opt('i', 'input', required = True)\n .opt('o', 'output', param = True, default = 'a.out')\n .opt('v', 'verbose', additive = True)\n .opt('p', 'ports', multi = True, parser = int)\n .opt('c', 'count', param = True, additive = True, parser = int, default = 0)\n .opt('q', 'quiet', name = 'verbose', additive = True, increment = -1)\n .parse() )\n\n print('optmap = %s' % repr(optmap))\n print('args = %s' % repr(args))\n\n $ python test.py --input a -qq -p 1 -p 2 -c -10000 -c 400 Hello Python\n\toptmap = {'output': 'a.out', 'count': -9600, 'safe': False, 'ports': [1, 2], 'input': 'a', 'verbose': -2}\n\targs = ['Hello', 'Python']\n\nMapping Functions to Subcommands: The SubcommandMap Object\n==========================================================\nVersion 0.4 brings the SubcommandMap object, which provides pretty semantics to mapping\nfunctions to subcommands, and declaring which subcommand is the default. It is common\nto write tools with subcommands, where the first element in argv after the program name\nindicates a subcommand. Examples are tools like 'git', which have many subcommands.\n\nSubcommandMap allows you to declare an instance, and then use decorators to wrap your\nfunctions and place them in a logical mapping from subcommand to function. The function\nwill receive all of argv as arguments, minus the first element if it is the name\nof a known subcommand.\n\nExample Usage\n-------------\n\nIn this example, our command supports two subcommands, with one of them being default.::\n\n from optspec import SubcommandMap\n\n subcom = SubcommandMap()\n\n @subcom.define('polite', default = True)\n def polite_version(argv):\n if len(argv) < 2:\n print(\"I'm sorry, I don't know who you are.\")\n\n else:\n print(\"Good morning, %s! What a lovely day!\" % argv[1])\n\n @subcom.define('rude')\n def rude_version(argv):\n if len(argv) < 2:\n print(\"Who the hell are you?\")\n\n else:\n print(\"%s?? What a stupid name!\" % argv[1])\n \n if __name__ == \"__main__\":\n subcom.invoke()\n\n $ python subcom-test.py\n I'm sorry, I don't know who you are.\n $ python subcom-test.py Lain\n Good morning, Lain! What a lovely day!\n $ python subcom-test.py rude\n Who the hell are you?\n $ python subcom-test.py rude Lain\n Lain?? What a stupid name!", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/lainproliant/python3-optspec", "keywords": "argv parsing commandline", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "optspec", "package_url": "https://pypi.org/project/optspec/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/optspec/", "project_urls": { "Homepage": "https://github.com/lainproliant/python3-optspec" }, "release_url": "https://pypi.org/project/optspec/0.6/", "requires_dist": null, "requires_python": "", "summary": "Wrapper around getopt for option mapping, counting, and parsing.", "version": "0.6" }, "last_serial": 2094284, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "b05952cf7f638a4c4f199e7cd7448f38", "sha256": "9bf078359353c13b13ad2bcf65c4fd45919ae5822031ac8c9fcb48f7b4c641bc" }, "downloads": -1, "filename": "optspec-0.1.tar.gz", "has_sig": false, "md5_digest": "b05952cf7f638a4c4f199e7cd7448f38", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4155, "upload_time": "2016-04-09T09:17:18", "url": "https://files.pythonhosted.org/packages/a6/e6/939c7b397abec277d20498b13a46c4a66c0399e0b021512dac3201ab75b5/optspec-0.1.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "2d04bab01ceb803cb91de5b784f4006f", "sha256": "434aeab64f86e142af85780a66ecaae712cce1690dc584e43de3018656c7d1f1" }, "downloads": -1, "filename": "optspec-0.3.tar.gz", "has_sig": false, "md5_digest": "2d04bab01ceb803cb91de5b784f4006f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4123, "upload_time": "2016-04-10T20:42:00", "url": "https://files.pythonhosted.org/packages/23/30/e859da223c6fbf36f3dfc59b40aa33d3038da6c32f0418a1cba418edc0c5/optspec-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "d86ec870f0d1313165bdb2caa3fcd308", "sha256": "27fff03a6d72eda75ceac707f71adb75cd04fde1d024f465a81d9b1baa05c3de" }, "downloads": -1, "filename": "optspec-0.4.tar.gz", "has_sig": false, "md5_digest": "d86ec870f0d1313165bdb2caa3fcd308", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5113, "upload_time": "2016-04-20T04:22:22", "url": "https://files.pythonhosted.org/packages/ed/81/5a23e52728d584ba29a19ea219cb1ba0410eeeca840c4417bbeb743b2631/optspec-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "650fcc24b3132cc93c0015d6eba47d55", "sha256": "db35c6183c349255725d42b0ce4e9023c6e232b2bcdf319a434b0a0dacf89e46" }, "downloads": -1, "filename": "optspec-0.5.tar.gz", "has_sig": false, "md5_digest": "650fcc24b3132cc93c0015d6eba47d55", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5206, "upload_time": "2016-05-01T23:58:55", "url": "https://files.pythonhosted.org/packages/ec/3e/61038e86872f8d104c358a8aa2b0e14e654b66b51bea7bc9b39c085ae4ab/optspec-0.5.tar.gz" } ], "0.6": [ { "comment_text": "", "digests": { "md5": "834a7d378dcbb20a00b450fb5a90c05c", "sha256": "8c9ba1b1740c03b29dbc3e2a36bd31fac8c355be1a5ddd8a80d0f4e603c622c1" }, "downloads": -1, "filename": "optspec-0.6.tar.gz", "has_sig": false, "md5_digest": "834a7d378dcbb20a00b450fb5a90c05c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5238, "upload_time": "2016-05-02T05:08:41", "url": "https://files.pythonhosted.org/packages/c4/fa/2bb58a7ce2d5839500c1d0854ac6dbef297023ba84e5e7593245ba40e71a/optspec-0.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "834a7d378dcbb20a00b450fb5a90c05c", "sha256": "8c9ba1b1740c03b29dbc3e2a36bd31fac8c355be1a5ddd8a80d0f4e603c622c1" }, "downloads": -1, "filename": "optspec-0.6.tar.gz", "has_sig": false, "md5_digest": "834a7d378dcbb20a00b450fb5a90c05c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5238, "upload_time": "2016-05-02T05:08:41", "url": "https://files.pythonhosted.org/packages/c4/fa/2bb58a7ce2d5839500c1d0854ac6dbef297023ba84e5e7593245ba40e71a/optspec-0.6.tar.gz" } ] }