Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/cli/__init__.py
# Copyright (C) 2017-2019 The Software Heritage developers | # Copyright (C) 2017-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import click | import click | ||||
import logging | import logging | ||||
logger = logging.getLogger(__name__) | from swh.core.cli import swh, CONTEXT_SETTINGS | ||||
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) | |||||
logger = logging.getLogger(__name__) | |||||
@click.group(context_settings=CONTEXT_SETTINGS) | if __name__ == '__main__': | ||||
# for bw compat (i.e. have the 'swh-deposit' command), should now use the | |||||
# master 'swh' command group defined in swh.core | |||||
@click.group('swh-deposit', context_settings=CONTEXT_SETTINGS) | |||||
@click.option('--log-level', '-l', default='INFO', | @click.option('--log-level', '-l', default='INFO', | ||||
type=click.Choice(logging._nameToLevel.keys()), | type=click.Choice(logging._nameToLevel.keys()), | ||||
help="Log level (default to INFO)") | help="Log level (default to INFO)") | ||||
@click.pass_context | @click.pass_context | ||||
def cli(ctx, log_level): | def deposit(ctx, log_level): | ||||
logger.setLevel(log_level) | logger.setLevel(log_level) | ||||
ctx.ensure_object(dict) | ctx.ensure_object(dict) | ||||
else: | |||||
@swh.group('deposit') | |||||
@click.pass_context | |||||
def deposit(ctx): | |||||
"""Deposit main command | |||||
""" | |||||
pass | |||||
def main(): | def main(): | ||||
logging.basicConfig() | logging.basicConfig() | ||||
from . import deposit # noqa | return deposit(auto_envvar_prefix='SWH_DEPOSIT') | ||||
# These import statements MUST be executed after defining the 'deposit' group | |||||
# since the subcommands in these are defined using this 'deposit' group. | |||||
from . import client # noqa | |||||
try: | try: | ||||
from . import admin # noqa | from . import admin # noqa | ||||
except ImportError: # server part is optional | except ImportError: # server part is optional | ||||
pass | pass | ||||
return cli(auto_envvar_prefix='SWH_DEPOSIT') | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |