Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 1 | # Copyright (c) 2016 Comcast Cable Communications Management, LLC. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at: |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | # Generate clicmd formatted output |
| 16 | |
Paul Vinciguerra | 464e5e0 | 2019-11-01 15:07:32 -0400 | [diff] [blame] | 17 | from . import process, parsers |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 18 | import os |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 19 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 20 | |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 21 | class SiphonCLICMD(process.Siphon): |
| 22 | |
| 23 | name = "clicmd" |
| 24 | identifier = "VLIB_CLI_COMMAND" |
| 25 | |
| 26 | def __init__(self, *args, **kwargs): |
| 27 | super(SiphonCLICMD, self).__init__(*args, **kwargs) |
| 28 | self._parser = parsers.MacroInitializer() |
| 29 | |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 30 | # Output renderers |
| 31 | |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 32 | def separate_page_names(self, group): |
| 33 | return self.page_label(group) + ".rst" |
| 34 | |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 35 | def index_sort_key(self, group): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 36 | _global = self._cmds["_global"] |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 37 | if group not in self._group: |
| 38 | return group |
| 39 | (directory, file) = self._group[group] |
| 40 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 41 | if file in _global and "group_label" in _global[file]: |
| 42 | return _global[file]["group_label"] |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 43 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 44 | if directory in _global and "group_label" in _global[directory]: |
| 45 | return _global[directory]["group_label"] |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 46 | |
| 47 | return group |
| 48 | |
| 49 | def item_sort_key(self, item): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 50 | return item["value"]["path"] |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 51 | |
| 52 | def item_label(self, group, item): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 53 | return "_".join( |
| 54 | (self.name, self.sanitize_label(self._cmds[group][item]["value"]["path"])) |
| 55 | ) |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 56 | |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 57 | def page_title(self, group): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 58 | _global = self._cmds["_global"] |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 59 | (directory, file) = self._group[group] |
| 60 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 61 | if file and file in _global and "group_label" in _global[file]: |
| 62 | return _global[file]["group_label"] |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 63 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 64 | if directory in _global and "group_label" in _global[directory]: |
| 65 | return _global[directory]["group_label"] |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 66 | |
| 67 | file_ext = os.path.basename(directory) |
| 68 | fname, ext = os.path.splitext(file_ext) |
| 69 | return "%s cli reference" % fname.capitalize() |
| 70 | |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 71 | |
| 72 | # Register our processor |
| 73 | process.siphons["clicmd"] = SiphonCLICMD |