async def create_pkg_type_markdown_string( bring: Bring, plugin_doc: Doc, header_level: int = 2, add_description_header: bool = True, ): header = "#" * header_level plugin_doc.extract_metadata("examples") if plugin_doc.get_help(default=None): help_str = plugin_doc.get_help() else: help_str = "No description available." if add_description_header: markdown_string = f"{header} Description\n" + help_str + "\n\n" else: markdown_string = help_str + "\n\n" examples: Optional[Mapping[str, Any]] = plugin_doc.get_metadata_value( "examples") if examples: examples_string = await create_source_examples_markdown_string( bring=bring, examples=examples, header_level=header_level) markdown_string += examples_string return markdown_string
def prepare_table_items( args: Mapping[str, Any], aliases: Mapping[str, Any]) -> List[MutableMapping[str, Any]]: items: List[MutableMapping] = [] for k, v in sorted(args.items()): arg_aliases = aliases.get(k, {}) # aliases_reverse: Dict[str, List[str]] = {} # allowed_no_alias = [] allowed = v.get("allowed", []) if k != "version": allowed = sorted(allowed) # for a in allowed: # if a in arg_aliases.keys(): # aliases_reverse.setdefault(arg_aliases[a], []).append(a) # else: # allowed_no_alias.append(a) # if v["default"] is not None: # default = v["default"] # else: # default = "" # if allowed_no_alias: # allowed_first = allowed_no_alias[0] # else: # allowed_first = "" # if v.get("required", True): # req = "yes" # else: # req = "no" # if allowed_first in aliases_reverse.keys() and aliases_reverse[allowed_first]: # alias = aliases_reverse[allowed_first][0] # else: # alias = "" doc = Doc(v.get("doc", {})) item = { "name": k, "desc": doc.get_short_help(), "type": v["type"], "required": v.get("required", True), "default": v.get("default", None), "allowed": allowed, "aliases": arg_aliases, } items.append(item) return items
async def get_info(self) -> Doc: args: Dict[str, Any] = {"include_metadata": True} if self.update: args["retrieve_config"] = {"metadata_max_age": 0} info: MutableMapping[str, Any] = await self.data.get_values( # type: ignore resolve=True ) # type: ignore metadata_timestamp = info["metadata_timestamp"] t = arrow.get(metadata_timestamp) doc_dict = dict(info["info"]) doc_dict["metadata_timestamp"] = t.humanize() if info["labels"]: doc_dict["labels"] = info["labels"] if info["tags"]: doc_dict["tags"] = info["tags"] doc_dict["uri"] = info["uri"] defaults = info["defaults"] if defaults: defaults_markdown: Union[str, Syntax] = create_dict_element( _theme=bring_code_theme, **defaults ) else: defaults_markdown = " -- no defaults --" doc_dict["defaults"] = defaults_markdown doc_dict["index_type"] = info["index_type"] config = info["index_type_config"] if not config: _config: Union[str, Syntax] = " -- no config --" else: _config = create_dict_element(_theme=bring_code_theme, **config) doc_dict["config"] = _config if self.display_packages: pkg_infos = wrap_async_task(self.data.get_all_pkg_values, "info") table = Table(box=box.SIMPLE, show_header=False, padding=(0, 2, 0, 0)) table.add_column("Name", no_wrap=True, style="bold deep_sky_blue4") table.add_column("Description", no_wrap=False, style="italic") for pkg, vals in sorted(pkg_infos.items()): slug = vals["info"].get("slug", "n/a") table.add_row(pkg, slug) doc_dict["packages"] = table doc = Doc( doc_dict, short_help_key=self._short_help_key, help_key=self._help_key ) return doc
async def get_info(self) -> Doc: args: Dict[str, Any] = {"include_metadata": True} if self.update: args["retrieve_config"] = {"metadata_max_age": 0} info = await self.data.get_info(**args) metadata = info["metadata"] age = arrow.get(metadata["timestamp"]) source = info["source"] result = dict(info["info"]) result = {} result["slug"] = info["info"].get("slug", "-- description --") desc = info["info"].get("desc", None) if desc: result["desc"] = desc result["pkg_type"] = source["type"] # result["info"] = info["info"] if info["labels"]: result["labels"] = info["labels"] if info["tags"]: result["tags"] = info["tags"] result["metadata_timestamp"] = age.humanize() args = metadata["pkg_args"] aliases = metadata["aliases"] arg_allowed_items: int = 10000 args_table = create_table_from_pkg_args( args=metadata["pkg_args"], aliases=aliases, limit_allowed=arg_allowed_items, show_headers=False, minimal=not self._display_full_args, ) result["args"] = args_table # result["args"] = metadata["pkg_args"] # result["aliases"] = aliases # result["version_list"] = metadata["version_list"] doc = Doc(result, short_help_key=self._short_help_key, help_key=self._help_key) return doc
async def get_info(self) -> Doc: vals = await self.data.get_values() config_source = vals["config_source"] info = vals["info"] info["path"] = config_source.get("full_path", "-- not available --") if vals["parent"]: info["parent context"] = vals["parent"] info["config_data"] = create_dict_element( _theme=bring_code_theme, _prefix=" \n", **vals["config"] ) info_data = Doc( info, short_help_key=self._short_help_key, help_key=self._help_key ) return info_data
def create_table_from_pkg_args( args: Mapping[str, Any], aliases: Mapping[str, Any], limit_allowed: Optional[int] = None, ) -> Table: table = Table(box=box.SIMPLE) table.add_column("Name", no_wrap=True, style="bold dark_orange") table.add_column("Description", no_wrap=False, style="italic") table.add_column("Type", no_wrap=True) table.add_column("Required", no_wrap=True) table.add_column("Default", no_wrap=True, style="deep_sky_blue4") table.add_column("Allowed", no_wrap=True) table.add_column("Alias", no_wrap=True) for k, v in sorted(args.items()): arg_aliases = aliases.get(k, {}) aliases_reverse: Dict[str, List[str]] = {} allowed_no_alias = [] allowed = v.get("allowed", []) if limit_allowed is not None and len(allowed) > limit_allowed: allowed = allowed[0:limit_allowed] + ["..."] if k != "version": allowed = sorted(allowed) for a in allowed: if a in arg_aliases.keys(): aliases_reverse.setdefault(arg_aliases[a], []).append(a) else: allowed_no_alias.append(a) if v["default"] is not None: default = v["default"] else: default = "" if allowed_no_alias: allowed_first = allowed_no_alias[0] else: allowed_first = "" doc = Doc(v.get("doc", {})) if v.get("required", True): req = "yes" else: req = "no" if allowed_first in aliases_reverse.keys( ) and aliases_reverse[allowed_first]: alias = aliases_reverse[allowed_first][0] else: alias = "" table.add_row(k, doc.get_short_help(), v["type"], req, default, allowed_first, alias) if (allowed_first in aliases_reverse.keys() and len(aliases_reverse[allowed_first]) > 1): for alias in aliases_reverse[allowed_first][1:]: table.add_row("", "", "", "", "", "", alias) if len(allowed_no_alias) > 1: for item in allowed_no_alias[1:]: if item in aliases_reverse.keys() and aliases_reverse[item]: alias = aliases_reverse[item][0] else: alias = "" table.add_row("", "", "", "", "", item, alias) if item in aliases_reverse.keys() and len( aliases_reverse[item]) > 1: for alias in aliases_reverse[item][1:]: table.add_row("", "", "", "", "", "", alias) table.add_row("", "", "", "", "", "", "") return table