1 # ============LICENSE_START=======================================================
3 # ================================================================================
4 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
19 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 from docutils.nodes import literal_block
24 from sphinx.domains import Domain
25 from sphinx.util.compat import Directive
29 from dcae_cli.cli import cli as group # PYTHONPATH dynamically altered in conf.py
32 def generate_help_texts(command, prefix):
33 ctx = click.Context(command)
36 command.get_help_option(ctx).opts[0],
37 command.get_help(ctx),
40 if isinstance(command, click.core.Group):
41 for c in command.list_commands(ctx):
42 c = command.resolve_command(ctx, [c])[1]
44 for h in generate_help_texts(c, prefix):
49 def find_script_callable(name):
50 return list(pkg_resources.iter_entry_points(
51 'console_scripts', name))[0].load()
54 def make_block(command, opt, content):
55 h = "$ {} {}\n".format(command, opt) + content
56 return literal_block(h, h, language='bash')
59 class ClickHelpDirective(Directive):
61 required_arguments = 1
64 root_cmd = self.arguments[0]
65 #group = find_script_callable(root_cmd)
66 return list(generate_help_texts(group, [root_cmd]))
69 class DcaeCliDomain(Domain):
73 'click-help': ClickHelpDirective,
78 app.add_domain(DcaeCliDomain)