def services( ctx: Configuration, args: List, incomplete: str ) -> List[Tuple[str, str]]: """Services.""" _init_ctx(ctx) try: response = api.get_services(ctx) except HTTPError: response = [] completions = [] # type: List[Tuple[str, str]] if response: for domain in response: domain_name = domain['domain'] servicesdict = domain['services'] for service in servicesdict: completions.append( ( "{}.{}".format(domain_name, service), servicesdict[service]['description'], ) ) completions.sort() return [c for c in completions if incomplete in c[0]] return completions
def services(ctx: Configuration, args: List, incomplete: str) -> List[Tuple[str, str]]: """Services.""" _init_ctx(ctx) try: response = api.get_services(ctx) except HTTPError: response = [] completions = [] # type: List[Tuple[str, str]] if response: for domain in response: domain_name = domain['domain'] servicesdict = domain['services'] for service in servicesdict: completions.append(( "{}.{}".format(domain_name, service), servicesdict[service]['description'], )) completions.sort() return [c for c in completions if incomplete in c[0]] return completions
def list_cmd(ctx: Configuration, servicefilter): """Get list of services.""" ctx.auto_output('table') services = api.get_services(ctx) result = [] # type: List[Dict[Any,Any]] if servicefilter == ".*": result = services else: result = services servicefilterre = reg.compile(servicefilter) # type: Pattern domains = [] for domain in services: domain_name = domain['domain'] domaindata = {} servicesdict = domain['services'] servicedata = {} for service in servicesdict: if servicefilterre.search( "{}.{}".format(domain_name, service) ): servicedata[service] = servicesdict[service] if servicedata: domaindata["services"] = servicedata domaindata["domain"] = domain_name domains.append(domaindata) result = domains flattenresult = [] # type: List[Dict[str,Any]] for domain in result: for service in domain['services']: item = {} item['domain'] = domain['domain'] item['service'] = service item = {**item, **domain['services'][service]} flattenresult.append(item) cols = [ ('DOMAIN', 'domain'), ('SERVICE', 'service'), ('DESCRIPTION', 'description'), ] ctx.echo( format_output( ctx, flattenresult, columns=ctx.columns if ctx.columns else cols ) )
def list_cmd(ctx: Configuration, servicefilter): """Get list of services.""" ctx.auto_output('table') services = api.get_services(ctx) result = [] # type: List[Dict[Any,Any]] if servicefilter == ".*": result = services else: result = services servicefilterre = reg.compile(servicefilter) # type: Pattern domains = [] for domain in services: domain_name = domain['domain'] domaindata = {} servicesdict = domain['services'] servicedata = {} for service in servicesdict: if servicefilterre.search( "{}.{}".format(domain_name, service) ): servicedata[service] = servicesdict[service] if servicedata: domaindata["services"] = servicedata domaindata["domain"] = domain_name domains.append(domaindata) result = domains flattenresult = [] # type: List[Dict[str,Any]] for domain in result: for service in domain['services']: item = {} item['domain'] = domain['domain'] item['service'] = service item = {**item, **domain['services'][service]} flattenresult.append(item) cols = [ ('DOMAIN', 'domain'), ('SERVICE', 'service'), ('DESCRIPTION', 'description'), ] ctx.echo( format_output( ctx, flattenresult, columns=ctx.columns if ctx.columns else cols ) )