Created
August 23, 2017 08:08
-
-
Save VITIMan/dd27e1eb77a22c5682abb602966ddb52 to your computer and use it in GitHub Desktop.
Snippets using argparse
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
| import argparse | |
| # https://stackoverflow.com/a/9377686 | |
| class UniqueAppendAction(argparse.Action): | |
| def __call__(self, parser, namespace, values, option_string=None): | |
| unique_values = set(values) | |
| setattr(namespace, self.dest, unique_values) | |
| servers = ["ApaServer", "BananServer", "GulServer", "SolServer", | |
| "RymdServer", "SkeppServer", "HavsServer", "SovServer" ] | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('-o', '--only', nargs='*', choices=servers, action=UniqueAppendAction, | |
| help='Space separated list of case sensitive server names to process') | |
| print parser.parse_args() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment