Skip to content

Commit 33b0a0a

Browse files
authored
fix(chore): use a callable for defaults (#559)
Without a callable the defaults are evaluated on import which causes unexpected errors with other commands.
1 parent eabe5bd commit 33b0a0a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

mergify_cli/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ async def get_default_token() -> str:
7070
@click.version_option(VERSION)
7171
@click.option(
7272
"--github-server",
73-
default=asyncio.run(get_default_github_server()),
73+
default=lambda: asyncio.run(get_default_github_server()),
7474
)
7575
@click.option(
7676
"--token",
77-
default=asyncio.run(get_default_token()),
77+
default=lambda: asyncio.run(get_default_token()),
7878
help="GitHub personal access token",
7979
)
8080
@click.pass_context

mergify_cli/stack/cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ async def edit() -> None:
7575
"--keep-pull-request-title-and-body",
7676
"-k",
7777
is_flag=True,
78-
default=asyncio.run(utils.get_default_keep_pr_title_body()),
78+
# NOTE: `flag_value` here is used to allow the default's lazy loading with `is_flag`
79+
flag_value=True,
80+
default=lambda: asyncio.run(utils.get_default_keep_pr_title_body()),
7981
help="Don't update the title and body of already opened pull requests. "
8082
"Default fetched from git config if added with `git config --add mergify-cli.stack-keep-pr-title-body true`",
8183
)
@@ -87,7 +89,7 @@ async def edit() -> None:
8789
"--trunk",
8890
"-t",
8991
type=click.UNPROCESSED,
90-
default=asyncio.run(utils.get_trunk()),
92+
default=lambda: asyncio.run(utils.get_trunk()),
9193
callback=trunk_type,
9294
help="Change the target branch of the stack.",
9395
)
@@ -168,7 +170,7 @@ async def push( # noqa: PLR0913, PLR0917
168170
"--trunk",
169171
"-t",
170172
type=click.UNPROCESSED,
171-
default=asyncio.run(utils.get_trunk()),
173+
default=lambda: asyncio.run(utils.get_trunk()),
172174
callback=trunk_type,
173175
help="Change the target branch of the stack.",
174176
)

0 commit comments

Comments
 (0)