docs: convert plugins doc md->rst
[vpp.git] / docs / _scripts / siphon / process_clicmd.py
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
17 from . import process, parsers
18 import os
19
20 class SiphonCLICMD(process.Siphon):
21
22     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
29     # Output renderers
30
31     def separate_page_names(self, group):
32         return self.page_label(group) + ".rst"
33
34     def index_sort_key(self, group):
35         _global = self._cmds['_global']
36         if group not in self._group:
37             return group
38         (directory, file) = self._group[group]
39
40         if file in _global and 'group_label' in _global[file]:
41             return _global[file]['group_label']
42
43         if directory in _global and 'group_label' in _global[directory]:
44             return _global[directory]['group_label']
45
46         return group
47
48     def item_sort_key(self, item):
49         return item['value']['path']
50
51     def item_label(self, group, item):
52         return "_".join((
53             self.name,
54             self.sanitize_label(self._cmds[group][item]['value']['path'])
55         ))
56
57     def page_title(self, group):
58         _global = self._cmds['_global']
59         (directory, file) = self._group[group]
60
61         if file and file in _global and 'group_label' in _global[file]:
62             return _global[file]['group_label']
63
64         if directory in _global and 'group_label' in _global[directory]:
65             return _global[directory]['group_label']
66
67         file_ext = os.path.basename(directory)
68         fname, ext = os.path.splitext(file_ext)
69         return "%s cli reference" % fname.capitalize()
70
71
72 # Register our processor
73 process.siphons["clicmd"] = SiphonCLICMD