Pumping pads as files into publishing frameworks!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.7 KiB

6 years ago
#!/usr/bin/env python3
import os
9 years ago
import sys
from pathlib import Path
from etherpump import __VERSION__
def subcommands():
"""List all sub-commands for the `--help` output."""
subcommands = []
all_files = os.listdir(Path().absolute() / 'etherpump' / 'commands')
modules = filter(lambda file: not file.startswith('__'), all_files)
for module in modules:
name = module.split('.py')[0]
subcommands.append(f' {name}')
return '\n'.join(subcommands)
usage = """
_
| |
_ _|_ | | _ ,_ _ _ _ _ _
|/ | |/ \ |/ / | |/ \_| | / |/ |/ | |/ \_
|__/|_/| |_/|__/ |_/|__/ \_/|_/ | | |_/|__/
/| /|
\| \|
Usage:
etherpump CMD
where CMD could be:
{}
For more information on each command try:
etherpump CMD --help
""".format(
subcommands()
)
9 years ago
try:
cmd = sys.argv[1]
if cmd.startswith("-"):
args = sys.argv
9 years ago
else:
args = sys.argv[2:]
if len(sys.argv) < 3:
if any(arg in args for arg in ['--help', '-h']):
print(usage)
sys.exit(0)
elif any(arg in args for arg in ['--version', '-v']):
print('etherpump {}'.format(__VERSION__))
sys.exit(0)
9 years ago
except IndexError:
print(usage)
sys.exit(0)
9 years ago
try:
# http://stackoverflow.com/questions/301134/dynamic-module-import-in-python
cmdmod = __import__(
"etherpump.commands.%s" % cmd, fromlist=["etherdump.commands"]
)
9 years ago
cmdmod.main(args)
6 years ago
except ImportError as e:
print("Error performing command '{0}'\n(python said: {1})\n".format(cmd, e))
print(usage)