43 lines
1005 B
Python
43 lines
1005 B
Python
import click
|
|
import os
|
|
import sys
|
|
import vultron.cmd
|
|
import vultron.display
|
|
import vultron.err
|
|
|
|
from vultron.cmds import *
|
|
|
|
@click.command()
|
|
@click.option("--help", is_flag=True)
|
|
@click.option("--api-key", type=str)
|
|
@click.option("--out",
|
|
type=click.Choice(vultron.display.FORMATS.keys()), default="table")
|
|
@click.argument("args", nargs=-1)
|
|
# FIXME: click should not show any help messages
|
|
def app(help, api_key, out, args):
|
|
env_key = os.getenv("VULTR_API_KEY")
|
|
|
|
if api_key is None and env_key:
|
|
api_key = env_key
|
|
|
|
shortcut = "help"
|
|
|
|
if len(args):
|
|
shortcut = args[0]
|
|
args = args[1:]
|
|
|
|
try:
|
|
vultron_cmd = vultron.cmd.find_cmd(shortcut)
|
|
vultron_api = vultron_cmd(sys.argv[0], api_key=api_key, out=out)
|
|
|
|
if len(args):
|
|
shortcut = args[0]
|
|
args = args[1:]
|
|
else:
|
|
shortcut = vultron_api.default
|
|
|
|
vultron_api.exec_shortcut(shortcut, *args)
|
|
except vultron.err.Error as err:
|
|
print(f"error: {err}", file=sys.stderr)
|
|
# FIXME: Activate help command
|