Skip to content

Commit

Permalink
allow 'run' command to pass --host/-h and --port/-p to invenio
Browse files Browse the repository at this point in the history
allows binding dev instances to other interfaces/ports
  • Loading branch information
dfdan committed Oct 6, 2020
1 parent b62b21a commit 6ba7ee7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 6 additions & 2 deletions invenio_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,18 @@ def demo(local):


@cli.command()
def run():
@click.option('--host', '-h', default='127.0.0.1',
help='bind address')
@click.option('--port', '-p', default=5000,
help='bind port')
def run(host, port):
"""Starts the local development server.
NOTE: this only makes sense locally so no --local option
"""
cli_config = CLIConfig()
commands = LocalCommands(cli_config)
commands.run()
commands.run(host=host, port=str(port))


@cli.command()
Expand Down
8 changes: 5 additions & 3 deletions invenio_cli/helpers/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def demo(self):
command = ['pipenv', 'run', 'invenio', 'rdm-records', 'demo']
subprocess.run(command, check=True)

def run(self):
def run(self, host, port):
"""Run development server and celery queue."""
self._ensure_containers_running()

Expand All @@ -250,11 +250,13 @@ def signal_handler(sig, frame):
run_env['FLASK_ENV'] = 'development'
server = subprocess.Popen([
'pipenv', 'run', 'invenio', 'run', '--cert',
'docker/nginx/test.crt', '--key', 'docker/nginx/test.key'
'docker/nginx/test.crt', '--key', 'docker/nginx/test.key',
'--host', host, '--port', port
], env=run_env)

click.secho(
'Instance running!\nVisit https://127.0.0.1:5000', fg='green')
'Instance running!\nVisit https://{}:{}'.format(host, port),
fg='green')
server.wait()

def destroy(self):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_helpers/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def test_localcommands_run(
fake_cli_config):
commands = LocalCommands(fake_cli_config)

commands.run()
commands.run(host='127.0.0.1', port='5000')

run_env = os.environ.copy()
run_env['FLASK_ENV'] = 'development'
Expand All @@ -305,7 +305,8 @@ def test_localcommands_run(
]),
call([
'pipenv', 'run', 'invenio', 'run', '--cert',
'docker/nginx/test.crt', '--key', 'docker/nginx/test.key'
'docker/nginx/test.crt', '--key', 'docker/nginx/test.key',
'--host', '127.0.0.1', '--port', '5000'
], env=run_env),
call().wait()
]
Expand Down

0 comments on commit 6ba7ee7

Please sign in to comment.