in disableDetective.py [0:0]
def setup_command_line(args = None) -> argparse.Namespace:
"""
Configures and reads command line arguments.
Returns:
An argparse.Namespace object containing parsed arguments.
Raises:
argpare.ArgumentTypeError if an invalid value is used for
master_account argument.
"""
def _master_account_type(val: str, pattern: str = r'[0-9]{12}'):
if not re.match(pattern, val):
raise argparse.ArgumentTypeError
return val
# Setup command line arguments
parser = argparse.ArgumentParser(description=('Unlink AWS Accounts from a central '
'Detective Account, or delete the entire Detective graph.'))
parser.add_argument('--master_account', type=_master_account_type,
required=True,
help="AccountId for Central AWS Account.")
parser.add_argument('--input_file', type=argparse.FileType('r'),
help=('Path to CSV file containing the list of '
'account IDs and Email addresses. '
'This does not need to be provided if you use the delete_graph flag.'))
parser.add_argument('--assume_role', type=str, required=True,
help="Role Name to assume in each account.")
parser.add_argument('--delete_graph', action='store_true',
help=('Delete the master Detective graph. '
'If not provided, you must provide an input file.'))
parser.add_argument('--disabled_regions', type=str,
help=('Regions to disable Detective. If not specified, '
'all available regions disabled.'))
args = parser.parse_args(args)
if not args.delete_graph and not args.input_file:
raise parser.error("Either an input file or the delete_graph flag should be provided.")
return args