Skip to content

Instantly share code, notes, and snippets.

@VITIMan
Created August 23, 2017 08:08
Show Gist options
  • Select an option

  • Save VITIMan/dd27e1eb77a22c5682abb602966ddb52 to your computer and use it in GitHub Desktop.

Select an option

Save VITIMan/dd27e1eb77a22c5682abb602966ddb52 to your computer and use it in GitHub Desktop.
Snippets using argparse
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