Skip to content

Commit d522335

Browse files
committed
replace kwargs with explicit arguments
1 parent e263df4 commit d522335

File tree

2 files changed

+68
-27
lines changed

2 files changed

+68
-27
lines changed

src/qbpm/launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def launch_qutebrowser(
10-
profile: Profile | None, foreground: bool, qb_args: tuple[str, ...]
10+
profile: Profile | None, foreground: bool, qb_args: tuple[str, ...] = ()
1111
) -> bool:
1212
qb = profile.cmdline() if profile else [qutebrowser_exe()]
1313
return launch(foreground, [*qb, *qb_args])

src/qbpm/main.py

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
from collections.abc import Callable
44
from dataclasses import dataclass
5+
from functools import wraps
56
from pathlib import Path
67
from typing import Any, NoReturn
78

@@ -22,7 +23,34 @@ class Context:
2223
profile_dir: Path
2324

2425

25-
def creator_options(f: Callable[..., Any]) -> Callable[..., Any]:
26+
@dataclass
27+
class CreatorOptions:
28+
qb_config_dir: Path | None
29+
launch: bool
30+
foreground: bool
31+
desktop_file: bool
32+
overwrite: bool
33+
34+
35+
def creator_options(orig: Callable[..., Any]) -> Callable[..., Any]:
36+
@wraps(orig)
37+
def command(
38+
qb_config_dir: Path | None,
39+
launch: bool,
40+
foreground: bool,
41+
desktop_file: bool,
42+
overwrite: bool,
43+
*args: Any,
44+
**kwargs: Any,
45+
) -> Any:
46+
return orig(
47+
*args,
48+
c_opts=CreatorOptions(
49+
qb_config_dir, launch, foreground, desktop_file, overwrite
50+
),
51+
**kwargs,
52+
)
53+
2654
for opt in reversed(
2755
[
2856
click.option(
@@ -54,8 +82,8 @@ def creator_options(f: Callable[..., Any]) -> Callable[..., Any]:
5482
),
5583
]
5684
):
57-
f = opt(f)
58-
return f
85+
command = opt(command)
86+
return command
5987

6088

6189
class LowerCaseFormatter(logging.Formatter):
@@ -96,10 +124,24 @@ def main(ctx: click.Context, profile_dir: Path | None, log_level: str) -> None:
96124
@click.argument("home_page", required=False)
97125
@creator_options
98126
@click.pass_obj
99-
def new(context: Context, profile_name: str, **kwargs: Any) -> None:
127+
def new(
128+
context: Context,
129+
profile_name: str,
130+
home_page: str | None,
131+
c_opts: CreatorOptions,
132+
) -> None:
100133
"""Create a new profile."""
101134
profile = Profile(profile_name, **vars(context))
102-
then_launch(profiles.new_profile, profile, **kwargs)
135+
exit_with(
136+
profiles.new_profile(
137+
profile,
138+
c_opts.qb_config_dir,
139+
home_page,
140+
c_opts.desktop_file,
141+
c_opts.overwrite,
142+
)
143+
and ((not c_opts.launch) or launch_qutebrowser(profile, c_opts.foreground))
144+
)
103145

104146

105147
@main.command()
@@ -111,27 +153,38 @@ def from_session(
111153
context: Context,
112154
session: str,
113155
profile_name: str | None,
114-
**kwargs: Any,
156+
c_opts: CreatorOptions,
115157
) -> None:
116158
"""Create a new profile from a saved qutebrowser session.
117159
SESSION may be the name of a session in the global qutebrowser profile
118160
or a path to a session yaml file.
119161
"""
120162
profile, session_path = session_info(session, profile_name, context)
121-
then_launch(operations.from_session, profile, session_path=session_path, **kwargs)
163+
exit_with(
164+
operations.from_session(
165+
profile,
166+
session_path,
167+
c_opts.qb_config_dir,
168+
c_opts.desktop_file,
169+
c_opts.overwrite,
170+
)
171+
and ((not c_opts.launch) or launch_qutebrowser(profile, c_opts.foreground))
172+
)
122173

123174

124-
@main.command(context_settings={"ignore_unknown_options": True})
175+
@main.command("launch", context_settings={"ignore_unknown_options": True})
125176
@click.argument("profile_name")
126177
@click.argument("qb_args", nargs=-1, type=click.UNPROCESSED)
127178
@click.option(
128179
"-f", "--foreground", is_flag=True, help="Run qutebrowser in the foreground."
129180
)
130181
@click.pass_obj
131-
def launch(context: Context, profile_name: str, **kwargs: Any) -> None:
182+
def launch_profile(
183+
context: Context, profile_name: str, foreground: bool, qb_args: tuple[str, ...]
184+
) -> None:
132185
"""Launch qutebrowser with a specific profile. All QB_ARGS are passed on to qutebrowser."""
133186
profile = Profile(profile_name, **vars(context))
134-
exit_with(launch_qutebrowser(profile, **kwargs))
187+
exit_with(launch_qutebrowser(profile, foreground, qb_args))
135188

136189

137190
@main.command(context_settings={"ignore_unknown_options": True})
@@ -147,12 +200,14 @@ def launch(context: Context, profile_name: str, **kwargs: Any) -> None:
147200
"-f", "--foreground", is_flag=True, help="Run qutebrowser in the foreground."
148201
)
149202
@click.pass_obj
150-
def choose(context: Context, **kwargs: Any) -> None:
203+
def choose(
204+
context: Context, menu: str | None, foreground: bool, qb_args: tuple[str, ...]
205+
) -> None:
151206
"""Choose a profile to launch.
152207
Support is built in for many X and Wayland launchers, as well as applescript dialogs.
153208
All QB_ARGS are passed on to qutebrowser.
154209
"""
155-
exit_with(choose_profile(profile_dir=context.profile_dir, **kwargs))
210+
exit_with(choose_profile(context.profile_dir, menu, foreground, qb_args))
156211

157212

158213
@main.command()
@@ -187,20 +242,6 @@ def desktop(
187242
exit_with(operations.desktop(profile))
188243

189244

190-
def then_launch(
191-
operation: Callable[..., bool],
192-
profile: Profile,
193-
launch: bool,
194-
foreground: bool,
195-
qb_args: tuple[str, ...] = (),
196-
**kwargs: Any,
197-
) -> None:
198-
exit_with(
199-
operation(profile, **kwargs)
200-
and ((not launch) or launch_qutebrowser(profile, foreground, qb_args))
201-
)
202-
203-
204245
def session_info(
205246
session: str, profile_name: str | None, context: Context
206247
) -> tuple[Profile, Path]:

0 commit comments

Comments
 (0)