Skip to content

Commit

Permalink
web: make host, port cli_config configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed Nov 18, 2024
1 parent 9900da3 commit 128053b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 19 additions & 2 deletions invenio_cli/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright (C) 2019-2021 CERN.
# Copyright (C) 2019 Northwestern University.
# Copyright (C) 2022 Forschungszentrum Jülich GmbH.
# Copyright (C) 2024 Graz University of Technology.
#
# Invenio-Cli is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -164,8 +165,18 @@ def run_group(ctx):
help="Enable/disable dockerized services (default: enabled).",
)
web_options = combine_decorators(
click.option("--host", "-h", default="127.0.0.1", help="The interface to bind to."),
click.option("--port", "-p", default=5000, help="The port to bind to."),
click.option(
"--host",
"-h",
default=None,
help="The interface to bind to. The default is defined in the CLIConfig.",
),
click.option(
"--port",
"-p",
default=None,
help="The port to bind to. The default is defined in the CLIConfig.",
),
click.option(
"--debug/--no-debug",
"-d/",
Expand All @@ -189,6 +200,9 @@ def run_web(cli_config, host, port, debug, services):
# fail and exit if containers are not running
handle_process_response(response)

host = host or cli_config.get_web_host()
port = port or cli_config.get_web_port()

commands = LocalCommands(cli_config)
processes = commands.run_web(host=host, port=str(port), debug=debug)
for proc in processes:
Expand Down Expand Up @@ -235,6 +249,9 @@ def run_all(cli_config, host, port, debug, services, celery_log_file):
# fail and exit if containers are not running
handle_process_response(response)

host = host or cli_config.get_web_host()
port = port or cli_config.get_web_port()

commands = LocalCommands(cli_config)
processes = commands.run_all(
host=host,
Expand Down
8 changes: 8 additions & 0 deletions invenio_cli/helpers/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ def get_search_host(self):
"localhost",
)

def get_web_port(self):
"""Returns web port."""
return self.config[CLIConfig.COOKIECUTTER_SECTION].get("web_port", "5000")

def get_web_host(self):
"""Returns web host."""
return self.config[CLIConfig.COOKIECUTTER_SECTION].get("web_host", "127.0.0.1")

def get_db_type(self):
"""Returns the database type (mysql, postgresql)."""
return self.config[CLIConfig.COOKIECUTTER_SECTION]["database"]
Expand Down

0 comments on commit 128053b

Please sign in to comment.