This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/cli.py

30 lines
787 B
Python

import os
import click.testing
import flask.cli
from ereuse_devicehub.config import DevicehubConfig
from ereuse_devicehub.devicehub import Devicehub
class DevicehubGroup(flask.cli.FlaskGroup):
# todo users cannot make cli to use a custom db this way!
CONFIG = DevicehubConfig
def main(self, *args, **kwargs):
# todo this should be taken as an argument for the cli
inventory = os.environ.get('dhi')
if not inventory:
raise ValueError('Please do "export dhi={inventory}"')
self.create_app = self.create_app_factory(inventory)
return super().main(*args, **kwargs)
@staticmethod
def create_app_factory(inventory):
return lambda: Devicehub(inventory)
@click.group(cls=DevicehubGroup)
def cli():
pass