50 lines
985 B
Python
50 lines
985 B
Python
import click
|
|
import os
|
|
import sys
|
|
import vultron.cmd
|
|
|
|
class Help(vultron.cmd.Command):
|
|
def init(self):
|
|
self.uses_api = False
|
|
|
|
def vultron_help(self, *args):
|
|
pass
|
|
|
|
class Account(vultron.cmd.Command):
|
|
def init(self):
|
|
self.default = "info"
|
|
|
|
def vultron_info(self, *args):
|
|
pass
|
|
|
|
@click.command()
|
|
@click.option("--help", is_flag=True)
|
|
@click.option("--api-key", type=str)
|
|
@click.argument("args", nargs=-1)
|
|
def app(help, api_key, 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)
|
|
|
|
if len(args):
|
|
shortcut = args[0]
|
|
args = args[1:]
|
|
else:
|
|
shortcut = vultron_api.default
|
|
|
|
vultron_fn = vultron_api.find(shortcut)
|
|
vultron_fn(*args)
|
|
except vultron.cmd.CmdNotFound as err:
|
|
print(err)
|