Created
May 4, 2015 10:49
-
-
Save mapix/764d8a10ccc699713582 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def checkRequiredArguments(opts, parser): | |
| missing_options = [] | |
| for option in parser.option_list: | |
| if re.match(r'^\[REQUIRED\]', option.help) and eval('opts.' + option.dest) == None: | |
| missing_options.extend(option._long_opts) | |
| if len(missing_options) > 0: | |
| parser.error('Missing REQUIRED parameters: ' + str(missing_options)) | |
| parser = OptionParser() | |
| parser.add_option("-s", "--start-date", help="[REQUIRED] Start date") | |
| parser.add_option("-e", "--end-date", dest="endDate", help="[REQUIRED] End date") | |
| (opts, args) = parser.parse_args(['-s', 'some-date']) | |
| checkRequiredArguments(opts, parser) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment