Fix command listing to work on pip package installs
This commit is contained in:
parent
e1691830b1
commit
d9988a932c
@ -1,36 +1,46 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
from importlib import import_module
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from etherpump import __VERSION__
|
from etherpump import __VERSION__
|
||||||
|
|
||||||
|
|
||||||
def subcommands():
|
def subcommands():
|
||||||
"""List all sub-commands for the `--help` output."""
|
"""List all sub-commands for the `--help` output."""
|
||||||
not_sub_commands = ['common.py', 'appendmeta.py', 'html5tidy.py', 'join.py']
|
output = []
|
||||||
subcommands = []
|
|
||||||
|
|
||||||
all_files = os.listdir(Path().absolute() / 'etherpump' / 'commands')
|
subcommands = [
|
||||||
modules = filter(
|
'creatediffhtml',
|
||||||
lambda file: not file.startswith('__')
|
'deletepad',
|
||||||
and not any(file == module for module in not_sub_commands),
|
'dumpcsv',
|
||||||
all_files,
|
'gethtml',
|
||||||
)
|
'gettext',
|
||||||
|
'index',
|
||||||
|
'init',
|
||||||
|
'list',
|
||||||
|
'listauthors',
|
||||||
|
'publication',
|
||||||
|
'pull',
|
||||||
|
'revisionscount',
|
||||||
|
'sethtml',
|
||||||
|
'settext',
|
||||||
|
'showmeta',
|
||||||
|
]
|
||||||
|
|
||||||
for module in modules:
|
for subcommand in subcommands:
|
||||||
name = module.split('.py')[0]
|
|
||||||
try:
|
try:
|
||||||
doc = import_module(f'etherpump.commands.{name}').__doc__
|
# http://stackoverflow.com/questions/301134/dynamic-module-import-in-python
|
||||||
|
doc = __import__(
|
||||||
|
"etherpump.commands.%s" % subcommand,
|
||||||
|
fromlist=["etherdump.commands"],
|
||||||
|
).__doc__
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
doc = ""
|
doc = ""
|
||||||
subcommands.append(f' {name}: {doc}')
|
output.append(f' {subcommand}: {doc}')
|
||||||
|
|
||||||
subcommands.sort()
|
output.sort()
|
||||||
|
|
||||||
return '\n'.join(subcommands)
|
return '\n'.join(output)
|
||||||
|
|
||||||
|
|
||||||
usage = """
|
usage = """
|
||||||
|
Loading…
Reference in New Issue
Block a user