Skip to content

Commit

Permalink
fix: make sure that envvars can override the default network option (#28
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fubuloubu authored Aug 18, 2023
1 parent 332236b commit 3b2d0f3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions silverback/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

import click
from ape.cli import AccountAliasPromptChoice, NetworkBoundCommand, network_option, verbosity_option
from ape.cli import AccountAliasPromptChoice, ape_cli_context, network_option, verbosity_option

from silverback._importer import import_from_string
from silverback.runner import LiveRunner
Expand All @@ -13,18 +13,23 @@ def cli():
"""Work with SilverBack applications in local context (using Ape)."""


@cli.command(cls=NetworkBoundCommand)
@cli.command()
@ape_cli_context()
@verbosity_option()
@network_option()
@network_option(default=None)
@click.option("--account", type=AccountAliasPromptChoice(), default=None)
@click.option("-x", "--max-exceptions", type=int, default=3)
@click.argument("path")
def run(network, account, max_exceptions, path):
os.environ["SILVERBACK_NETWORK_CHOICE"] = network
def run(cli_ctx, network, account, max_exceptions, path):
if network:
os.environ["SILVERBACK_NETWORK_CHOICE"] = network
else:
network = os.environ.get("SILVERBACK_NETWORK_CHOICE", "")

if account:
os.environ["SILVERBACK_SIGNER_ALIAS"] = account.alias.replace("dev_", "TEST::")

app = import_from_string(path)
runner = LiveRunner(app, max_exceptions=max_exceptions)
asyncio.run(runner.run())
with cli_ctx.network_manager.parse_network_choice(network):
app = import_from_string(path)
runner = LiveRunner(app, max_exceptions=max_exceptions)
asyncio.run(runner.run())

0 comments on commit 3b2d0f3

Please sign in to comment.