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.
2019-01-23 15:55:04 +00:00
|
|
|
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):
|
2019-02-04 12:01:36 +00:00
|
|
|
# todo users cannot make cli to use a custom db this way!
|
2019-01-23 15:55:04 +00:00
|
|
|
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
|