class Hubspot3CLIWrapper: # pylint: disable=empty-docstring __doc__ = """ Hubspot3 CLI To get a list of supported operations, call this CLI without the "--help" option. The API client can be configured by providing options BEFORE specifying the operation to execute. KWARGS are: [--config CONFIG_FILE_PATH] {} """.format(build_usage_string(Hubspot3).split("\n")[-1]) # Properties to ignore during discovery. The "me" property must be ignored # as it would already perform an API request while being discovered and the # "usage_limits" property does not contain an API. # Extend this tuple if more properties that aren't API clients are added to # the Hubspot3 class. IGNORED_PROPERTIES = ("me", "usage_limits") def __init__(self, **kwargs): # If no arguments were supplied at all, the desired outcome is likely # the list of operations/clients. Therefore disable authentication to # stop the Hubspot3 initializer from raising an exception since there # is neither an API key nor an access token. if not kwargs: kwargs["disable_auth"] = True # If a config file was specified, read its settings and merge the CLI # options into them. config_file = kwargs.pop("config", None) if config_file is not None: config = get_config_from_file(config_file) kwargs = dict(config, **kwargs) # Initialize the main client, discover all sub-clients and set them as # attributes on this wrapper so Fire can discover them. hubspot3 = Hubspot3(**kwargs) self._clients = self._discover_clients(hubspot3) for attr, client in self._clients.items(): setattr(self, attr, ClientCLIWrapper(client)) def __dir__(self): return self._clients # Let Fire only discover the client attributes. def __str__(self): return "Hubspot3 CLI" def _discover_clients(self, hubspot3: Hubspot3) -> Dict[str, BaseClient]: """Find all client instance properties on the given Hubspot3 object.""" clients = {} for attr in dir(hubspot3.__class__): # Find properties by searching the class first - that way, a call # to getattr doesn't run the properties code on the object. if (attr.startswith("_") or attr in self.IGNORED_PROPERTIES or not isinstance( getattr(hubspot3.__class__, attr), property)): continue client = getattr(hubspot3, attr) if isinstance(client, BaseClient): clients[attr] = client return clients
def _build_wrapper_doc(self, method: types.MethodType) -> str: """Build a helpful docstring for a wrapped API method.""" return "\n".join(( method.__doc__ or "", "", "Supported ARGS/KWARGS are:", build_usage_string(method), "", 'The token "{}" may be used as an argument value, which will cause JSON data to be ' "read from stdin and used as the actual argument value.".format( self.STDIN_TOKEN), ))