From cd6c285cc6c2274e6b42cc452ba4a61a3487ca23 Mon Sep 17 00:00:00 2001 From: Eric Fried Date: Mon, 28 Oct 2019 17:27:38 -0500 Subject: neutron: autogenerate docs $namespace = openstack.network.v2 The subcommand documents for $namespace were hardcoded and thus prone to drift over time. This commit removes the hardcoded content and uses the autoprogram-cliff directive to generate them automatically from the subcommand configuration classes. This one turned out to be quite involved, because we support both neutron and nova-network. When running in a real cloud, the command classes detect whether the neutron service is present, assume nova-network if that service is not found, and only add parser options relevant to the detected service. But the docs need to present both sets of options. This was easy enough when they were hardcoded, but required a bit of additional infrastructure for generated docs. Change-Id: I426261eb1d86bcc68656aabd61f10b7f082da402 --- openstackclient/network/v2/security_group.py | 46 ++++++++++++++++++---------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'openstackclient/network/v2/security_group.py') diff --git a/openstackclient/network/v2/security_group.py b/openstackclient/network/v2/security_group.py index 38b4e97a..9f0ca0a1 100644 --- a/openstackclient/network/v2/security_group.py +++ b/openstackclient/network/v2/security_group.py @@ -119,10 +119,13 @@ class CreateSecurityGroup(common.NetworkAndComputeShowOne): parser.add_argument( '--project', metavar='', - help=_("Owner's project (name or ID)") + help=self.enhance_help_neutron(_("Owner's project (name or ID)")) ) - identity_common.add_project_domain_option_to_parser(parser) - _tag.add_tag_option_to_parser_for_create(parser, _('security group')) + identity_common.add_project_domain_option_to_parser( + parser, enhance_help=self.enhance_help_neutron) + _tag.add_tag_option_to_parser_for_create( + parser, _('security group'), + enhance_help=self.enhance_help_neutron) return parser def _get_description(self, parsed_args): @@ -202,22 +205,28 @@ class ListSecurityGroup(common.NetworkAndComputeLister): _description = _("List security groups") def update_parser_network(self, parser): - # Maintain and hide the argument for backwards compatibility. - # Network will always return all projects for an admin. - parser.add_argument( - '--all-projects', - action='store_true', - default=False, - help=argparse.SUPPRESS, - ) + if not self.is_docs_build: + # Maintain and hide the argument for backwards compatibility. + # Network will always return all projects for an admin. + parser.add_argument( + '--all-projects', + action='store_true', + default=False, + help=argparse.SUPPRESS, + ) + parser.add_argument( '--project', metavar='', - help=_("List security groups according to the project " - "(name or ID)") + help=self.enhance_help_neutron( + _("List security groups according to the project (name or " + "ID)")) ) - identity_common.add_project_domain_option_to_parser(parser) - _tag.add_tag_filtering_option_to_parser(parser, _('security group')) + identity_common.add_project_domain_option_to_parser( + parser, enhance_help=self.enhance_help_neutron) + _tag.add_tag_filtering_option_to_parser( + parser, _('security group'), + enhance_help=self.enhance_help_neutron) return parser def update_parser_compute(self, parser): @@ -225,7 +234,8 @@ class ListSecurityGroup(common.NetworkAndComputeLister): '--all-projects', action='store_true', default=False, - help=_("Display information from all projects (admin only)") + help=self.enhance_help_nova_network( + _("Display information from all projects (admin only)")) ) return parser @@ -307,7 +317,9 @@ class SetSecurityGroup(common.NetworkAndComputeCommand): return parser def update_parser_network(self, parser): - _tag.add_tag_option_to_parser_for_set(parser, _('security group')) + _tag.add_tag_option_to_parser_for_set( + parser, _('security group'), + enhance_help=self.enhance_help_neutron) return parser def take_action_network(self, client, parsed_args): -- cgit v1.2.1