Skip to content

Commit

Permalink
fix(chore): use a callable for defaults (#559)
Browse files Browse the repository at this point in the history
Without a callable the defaults are evaluated on import which causes unexpected errors with other commands.
  • Loading branch information
lecrepont01 authored Nov 29, 2024
1 parent eabe5bd commit 33b0a0a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions mergify_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ async def get_default_token() -> str:
@click.version_option(VERSION)
@click.option(
"--github-server",
default=asyncio.run(get_default_github_server()),
default=lambda: asyncio.run(get_default_github_server()),
)
@click.option(
"--token",
default=asyncio.run(get_default_token()),
default=lambda: asyncio.run(get_default_token()),
help="GitHub personal access token",
)
@click.pass_context
Expand Down
8 changes: 5 additions & 3 deletions mergify_cli/stack/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ async def edit() -> None:
"--keep-pull-request-title-and-body",
"-k",
is_flag=True,
default=asyncio.run(utils.get_default_keep_pr_title_body()),
# NOTE: `flag_value` here is used to allow the default's lazy loading with `is_flag`
flag_value=True,
default=lambda: asyncio.run(utils.get_default_keep_pr_title_body()),
help="Don't update the title and body of already opened pull requests. "
"Default fetched from git config if added with `git config --add mergify-cli.stack-keep-pr-title-body true`",
)
Expand All @@ -87,7 +89,7 @@ async def edit() -> None:
"--trunk",
"-t",
type=click.UNPROCESSED,
default=asyncio.run(utils.get_trunk()),
default=lambda: asyncio.run(utils.get_trunk()),
callback=trunk_type,
help="Change the target branch of the stack.",
)
Expand Down Expand Up @@ -168,7 +170,7 @@ async def push( # noqa: PLR0913, PLR0917
"--trunk",
"-t",
type=click.UNPROCESSED,
default=asyncio.run(utils.get_trunk()),
default=lambda: asyncio.run(utils.get_trunk()),
callback=trunk_type,
help="Change the target branch of the stack.",
)
Expand Down

0 comments on commit 33b0a0a

Please sign in to comment.