Source code for idmtools_platform_comps.cli.cli_functions
"""idmtools cli utils.Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved."""fromdataclassesimportFieldfromtypingimportDict,Tuple
[docs]defvalidate_range(value:float,min:float,max:float)->Tuple[bool,str]:""" Function used to validate an integer value between min and max. Args: value: The value set by the user min: Minimum value max: Maximum value Returns: tuple with validation result and error message if needed """ifmin<=value<=max:returnTrue,''returnFalse,f"The value needs to be between {min} and {max}"
[docs]defenvironment_list(previous_settings:Dict,current_field:Field)->Dict:""" Allows the CLI to provide a list of available environments. Uses the previous_settings to get the endpoint to query for environments Args: previous_settings: previous settings set by the user in the CLI. current_field: Current field specs Returns: updates to the choices and default """fromCOMPSimportClientClient.login(previous_settings["endpoint"])client=Client.get("environments")environment_choices=[]forenvironment_infoinclient.json()["Environments"]:environment_choices.append(environment_info["EnvironmentName"])# Set a valid defaultifcurrent_field.defaultnotinenvironment_choices:default_env=environment_choices[0]else:default_env=current_field.defaultreturn{"choices":environment_choices,"default":default_env}