boxespy/scripts/boxes

51 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
from __future__ import print_function
import argparse
import os
import sys
from pprint import pprint
try:
import boxes
except ImportError:
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/..")
import boxes
import boxes.generators
def printusage():
print("""Usage:
boxes [NAME] [options]
--list list possible names
--help show help for given NAME
""")
def main():
modules = boxes.generators.getAllGeneratorModules()
del modules['_template']
if len(sys.argv) == 1:
printusage()
elif (sys.argv[1] in modules or
(sys.argv[1].startswith("--generator=") and
sys.argv[1][12:] in modules)):
if sys.argv[1].startswith("--generator="):
sys.argv[1] = sys.argv[1][12:]
name = sys.argv[1]
sys.argv[0] = "%s %s" % (sys.argv[0], sys.argv[1])
sys.argv[1] = '--tab="0"'
del sys.argv[0]
del sys.argv[1]
modules[name].main()
elif sys.argv[1] == '--list':
print("Available generators:")
for name in sorted(modules):
if not hasattr(modules[name], "main"):
continue
print(" * ", name)
else:
print("Unknown generator name. Use boxes --list to get a list of available commands.")
main()