https://github.com/tintinweb/legacyoptparse
Simple to use Optparser with minimal dependencies and automatic usage/help generation
https://github.com/tintinweb/legacyoptparse
Last synced: about 1 month ago
JSON representation
Simple to use Optparser with minimal dependencies and automatic usage/help generation
- Host: GitHub
- URL: https://github.com/tintinweb/legacyoptparse
- Owner: tintinweb
- License: gpl-2.0
- Created: 2013-01-08T21:00:55.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-08-19T18:24:21.000Z (almost 13 years ago)
- Last Synced: 2026-02-15T16:40:32.234Z (6 months ago)
- Language: Python
- Homepage:
- Size: 121 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
LegacyOptparse
==============
Simple to use Optparser with minimal dependencies (getopt,sys,os)
Features
--------
* easy to use interface (see example)
* forced helptext
* default values for options
* mandatory options
Example
--------
code (see example.py):
import SimpleOptparse
if __name__ == '__main__':
# define the options we want to catch on the commandline
# Format:
# ((long_option,short_option), a short helpline for this option): default value
#
optDef = {
(('--help', '-h') ,"This help"): False,
(('--verbose', '-v') ,"Enable verbose output"): False,
(('--timeout', '-t') ,"Timeout for the console to stay open"): 5,
(('--branch', '-b') ,"use specific branch "): '1.1',
(('--magic' , '-m') ,"insert random magic values here"): None,
(('--deluxe', '-d') ,"Deluxe Option cost more than a million"): False,
(('--cant-afford','-c') ,"sure you cant! ha ha ha"): False,
(('--manD', '1') ,"This is a mandatory option!"): SimpleOptparse.MANDATORY,
}
# do the magic
options,arguments= SimpleOptparse.parseOpts(optDef)
# if no option was hit it will print the usage/help & exit
# if options were hit, it returns a tuple in the following format:
#
# ( {dictionary of all parsed options}, [a list of optional arguments])
print options
print arguments
run:
example.py
output:
Usage: example.py --manD= [OPTIONS] [Argument(s) ...]
Mandatory arguments to long options are mandatory for short options too.
-v, --verbose Enable verbose output.
-t , --timeout= Timeout for the console to stay open.
*** DEFAULT='5'
-b , --branch= use specific branch .
*** DEFAULT='1.1'
-c, --cant-afford sure you cant! ha ha ha.
-h, --help This help.
-d, --deluxe Deluxe Option cost more than a million.
1, --manD This is a mandatory option!.
-m , --magic= insert random magic values here.
*** DEFAULT='None'