Alphabetize functions.
This commit is contained in:
parent
6c063fd187
commit
40410496fc
1 changed files with 19 additions and 19 deletions
|
@ -10,6 +10,19 @@ HELPSTRINGS = {'', 'help', '-h', '--help'}
|
||||||
|
|
||||||
# INTERNALS
|
# INTERNALS
|
||||||
################################################################################
|
################################################################################
|
||||||
|
def add_previews(docstring, sub_docstrings) -> str:
|
||||||
|
'''
|
||||||
|
Given a primary docstring which contains {command_name} formatting elements,
|
||||||
|
and a dict of sub_docstrings of {command_name: docstring}, insert previews
|
||||||
|
of each command into the primary docstring.
|
||||||
|
'''
|
||||||
|
previews = {
|
||||||
|
sub_name: docstring_preview(sub_text)
|
||||||
|
for (sub_name, sub_text) in sub_docstrings.items()
|
||||||
|
}
|
||||||
|
docstring = docstring.format(**previews)
|
||||||
|
return docstring
|
||||||
|
|
||||||
def can_use_bare(parser) -> bool:
|
def can_use_bare(parser) -> bool:
|
||||||
'''
|
'''
|
||||||
Return true if the given parser has no required arguments, ie can run bare.
|
Return true if the given parser has no required arguments, ie can run bare.
|
||||||
|
@ -60,31 +73,18 @@ def docstring_preview(text) -> str:
|
||||||
text = text.split('\n\n')[0].strip()
|
text = text.split('\n\n')[0].strip()
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def listget(li, index, fallback=None):
|
|
||||||
try:
|
|
||||||
return li[index]
|
|
||||||
except IndexError:
|
|
||||||
return fallback
|
|
||||||
|
|
||||||
def add_previews(docstring, sub_docstrings) -> str:
|
|
||||||
'''
|
|
||||||
Given a primary docstring which contains {command_name} formatting elements,
|
|
||||||
and a dict of sub_docstrings of {command_name: docstring}, insert previews
|
|
||||||
of each command into the primary docstring.
|
|
||||||
'''
|
|
||||||
previews = {
|
|
||||||
sub_name: docstring_preview(sub_text)
|
|
||||||
for (sub_name, sub_text) in sub_docstrings.items()
|
|
||||||
}
|
|
||||||
docstring = docstring.format(**previews)
|
|
||||||
return docstring
|
|
||||||
|
|
||||||
def get_subparser_action(parser):
|
def get_subparser_action(parser):
|
||||||
for action in parser._actions:
|
for action in parser._actions:
|
||||||
if isinstance(action, argparse._SubParsersAction):
|
if isinstance(action, argparse._SubParsersAction):
|
||||||
return action
|
return action
|
||||||
raise TypeError('Couldn\'t locate the SubParsersAction.')
|
raise TypeError('Couldn\'t locate the SubParsersAction.')
|
||||||
|
|
||||||
|
def listget(li, index, fallback=None):
|
||||||
|
try:
|
||||||
|
return li[index]
|
||||||
|
except IndexError:
|
||||||
|
return fallback
|
||||||
|
|
||||||
def set_alias_docstrings(sub_docstrings, subparser_action) -> dict:
|
def set_alias_docstrings(sub_docstrings, subparser_action) -> dict:
|
||||||
'''
|
'''
|
||||||
When using subparser aliases:
|
When using subparser aliases:
|
||||||
|
|
Loading…
Reference in a new issue