blob: 4bf84edf0868b44b99b034fc7fe6937044a27f4d [file] [log] [blame]
Chris Luke90f52bf2016-09-12 08:55:13 -04001# 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 Vinciguerra464e5e02019-11-01 15:07:32 -040017from . import process, parsers
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020018import os
Chris Luke90f52bf2016-09-12 08:55:13 -040019
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020020
Chris Luke90f52bf2016-09-12 08:55:13 -040021class SiphonCLICMD(process.Siphon):
Chris Luke90f52bf2016-09-12 08:55:13 -040022 name = "clicmd"
23 identifier = "VLIB_CLI_COMMAND"
24
25 def __init__(self, *args, **kwargs):
26 super(SiphonCLICMD, self).__init__(*args, **kwargs)
27 self._parser = parsers.MacroInitializer()
28
Chris Luke90f52bf2016-09-12 08:55:13 -040029 # Output renderers
30
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020031 def separate_page_names(self, group):
32 return self.page_label(group) + ".rst"
33
Chris Luke90f52bf2016-09-12 08:55:13 -040034 def index_sort_key(self, group):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020035 _global = self._cmds["_global"]
Chris Luke90f52bf2016-09-12 08:55:13 -040036 if group not in self._group:
37 return group
38 (directory, file) = self._group[group]
39
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020040 if file in _global and "group_label" in _global[file]:
41 return _global[file]["group_label"]
Chris Luke90f52bf2016-09-12 08:55:13 -040042
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020043 if directory in _global and "group_label" in _global[directory]:
44 return _global[directory]["group_label"]
Chris Luke90f52bf2016-09-12 08:55:13 -040045
46 return group
47
48 def item_sort_key(self, item):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020049 return item["value"]["path"]
Chris Luke90f52bf2016-09-12 08:55:13 -040050
51 def item_label(self, group, item):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020052 return "_".join(
53 (self.name, self.sanitize_label(self._cmds[group][item]["value"]["path"]))
54 )
Chris Luke90f52bf2016-09-12 08:55:13 -040055
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020056 def page_title(self, group):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020057 _global = self._cmds["_global"]
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020058 (directory, file) = self._group[group]
59
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020060 if file and file in _global and "group_label" in _global[file]:
61 return _global[file]["group_label"]
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020062
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020063 if directory in _global and "group_label" in _global[directory]:
64 return _global[directory]["group_label"]
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020065
66 file_ext = os.path.basename(directory)
67 fname, ext = os.path.splitext(file_ext)
68 return "%s cli reference" % fname.capitalize()
69
Chris Luke90f52bf2016-09-12 08:55:13 -040070
71# Register our processor
72process.siphons["clicmd"] = SiphonCLICMD