Skip to content
Snippets Groups Projects
Commit 302700f0 authored by Nicolas Dandrimont's avatar Nicolas Dandrimont
Browse files

cli: Allow adding a Notes section between Options and Commands

This is useful to document the interaction between options
parent 0406c88d
No related branches found
No related tags found
1 merge request!101cli: Allow adding a Notes section between Options and Commands
......@@ -3,8 +3,9 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import click
import logging
import click
import pkg_resources
LOG_LEVEL_NAMES = ['NOTSET', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
......@@ -15,7 +16,12 @@ logger = logging.getLogger(__name__)
class AliasedGroup(click.Group):
'A simple Group that supports command aliases'
'''A simple Group that supports command aliases, as well as notes related to
options'''
def __init__(self, name=None, commands=None, **attrs):
self.option_notes = attrs.pop('option_notes', None)
super().__init__(name, commands, **attrs)
@property
def aliases(self):
......@@ -31,6 +37,13 @@ class AliasedGroup(click.Group):
name = name.name
self.aliases[alias] = name
def format_options(self, ctx, formatter):
click.Command.format_options(self, ctx, formatter)
if self.option_notes:
with formatter.section('Notes'):
formatter.write_text(self.option_notes)
self.format_commands(ctx, formatter)
@click.group(context_settings=CONTEXT_SETTINGS, cls=AliasedGroup)
@click.option('--log-level', '-l', default='INFO',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment