diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -50,6 +50,8 @@ entry_points=''' [console_scripts] swh-storage=swh.storage.cli:main + [swh.cli.subcommands] + storage=swh.storage.cli:storage ''', setup_requires=['vcversioner'], install_requires=parse_requirements() + parse_requirements('swh'), diff --git a/swh/storage/cli.py b/swh/storage/cli.py --- a/swh/storage/cli.py +++ b/swh/storage/cli.py @@ -3,23 +3,42 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +import logging + import click +from swh.core.cli import CONTEXT_SETTINGS from swh.storage.api.server import load_and_check_config, app -@click.command() +@click.group(name='storage', context_settings=CONTEXT_SETTINGS) +@click.pass_context +def storage(ctx): + '''Software Heritage Storage tools.''' + pass + + +@storage.command(name='rpc-serve') @click.argument('config-path', required=1) @click.option('--host', default='0.0.0.0', help="Host to run the server") @click.option('--port', default=5002, type=click.INT, help="Binding port of the server") -@click.option('--debug/--nodebug', default=True, +@click.option('--debug/--no-debug', default=True, help="Indicates if the server should run in debug mode") -def main(config_path, host, port, debug): +def serve(config_path, host, port, debug): + '''Software Heritage Storage RPC (standalone) server. + + Do NOT use this in a production environment. + ''' api_cfg = load_and_check_config(config_path, type='any') app.config.update(api_cfg) app.run(host, port=int(port), debug=bool(debug)) +def main(): + logging.basicConfig() + return serve(auto_envvar_prefix='SWH_STORAGE') + + if __name__ == '__main__': main()