You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
697 B

#!/usr/bin/env python
import argparse
def parse_roles(file_path):
"""
Parse the --roles argument out of the provided file.
Args:
file_path (str): The full path to the file to parse
Returns:
roles (list): Either a list of string roles, or an empty list if the file doesn't contain a --roles argument
"""
with open(file_path, mode='r') as f:
file_text = [line.strip() for line in f]
parser = argparse.ArgumentParser()
parser.add_argument('--roles')
args = parser.parse_known_args(file_text)
try:
roles = args[0].roles.split(':')
except AttributeError:
roles = []
return roles