25
25
@click .pass_context
26
26
def main (ctx , profile_dir : Path ) -> None :
27
27
# TODO version
28
- ctx .ensure_object (dict )
29
- ctx .obj ["PROFILE_DIR" ] = profile_dir
28
+ ctx .obj = profile_dir
30
29
31
30
32
31
@main .command ()
@@ -36,10 +35,10 @@ def main(ctx, profile_dir: Path) -> None:
36
35
@click .option ("--overwrite" , is_flag = True )
37
36
@click .option ("-l" , "--launch" , is_flag = True )
38
37
@click .option ("-f" , "--foreground" , is_flag = True )
39
- @click .pass_context
40
- def new (ctx , profile_name : str , ** kwargs ):
38
+ @click .pass_obj
39
+ def new (profile_dir : Path , profile_name : str , ** kwargs ):
41
40
"""Create a new profile."""
42
- profile = Profile (profile_name , ctx . obj [ "PROFILE_DIR" ] )
41
+ profile = Profile (profile_name , profile_dir )
43
42
then_launch (profiles .new_profile , profile , ** kwargs )
44
43
45
44
@@ -50,9 +49,9 @@ def new(ctx, profile_name: str, **kwargs):
50
49
@click .option ("--overwrite" , is_flag = True )
51
50
@click .option ("-l" , "--launch" , is_flag = True )
52
51
@click .option ("-f" , "--foreground" , is_flag = True )
53
- @click .pass_context
52
+ @click .pass_obj
54
53
def from_session (
55
- ctx ,
54
+ profile_dir : Path ,
56
55
session : str ,
57
56
profile_name : Optional [str ],
58
57
** kwargs ,
@@ -61,30 +60,30 @@ def from_session(
61
60
SESSION may be the name of a session in the global qutebrowser profile
62
61
or a path to a session yaml file.
63
62
"""
64
- profile , session_path = session_info (session , profile_name , ctx . obj [ "PROFILE_DIR" ] )
63
+ profile , session_path = session_info (session , profile_name , profile_dir )
65
64
then_launch (operations .from_session , profile , session_path = session_path , ** kwargs )
66
65
67
66
68
67
@main .command ()
69
68
@click .argument ("profile_name" )
70
- @click .pass_context
69
+ @click .pass_obj
71
70
def desktop (
72
- ctx ,
71
+ profile_dir : Path ,
73
72
profile_name : str ,
74
73
):
75
74
"""Create a desktop file for an existing profile."""
76
- profile = Profile (profile_name , ctx . obj [ "PROFILE_DIR" ] )
75
+ profile = Profile (profile_name , profile_dir )
77
76
exit_with (operations .desktop (profile ))
78
77
79
78
80
79
@main .command ()
81
80
@click .argument ("profile_name" )
82
81
@click .option ("-c" , "--create" , is_flag = True )
83
82
@click .option ("-f" , "--foreground" , is_flag = True )
84
- @click .pass_context
85
- def launch (ctx , profile_name : str , ** kwargs ):
83
+ @click .pass_obj
84
+ def launch (profile_dir : Path , profile_name : str , ** kwargs ):
86
85
"""Launch qutebrowser with a specific profile."""
87
- profile = Profile (profile_name , ctx . obj [ "PROFILE_DIR" ] )
86
+ profile = Profile (profile_name , profile_dir )
88
87
# TODO qb args
89
88
exit_with (operations .launch (profile , qb_args = [], ** kwargs ))
90
89
@@ -97,34 +96,32 @@ def launch(ctx, profile_name: str, **kwargs):
97
96
help = f"A dmenu-compatible command or one of the following supported menus: { ', ' .join (sorted (SUPPORTED_MENUS ))} " ,
98
97
)
99
98
@click .option ("-f" , "--foreground" , is_flag = True )
100
- @click .pass_context
101
- def choose (ctx , ** kwargs ):
99
+ @click .pass_obj
100
+ def choose (profile_dir : Path , ** kwargs ):
102
101
"""Choose a profile to launch.
103
102
Support is built in for many X and Wayland launchers, as well as applescript dialogs.
104
103
"""
105
104
# TODO qb args
106
- exit_with (
107
- operations .choose (profile_dir = ctx .obj ["PROFILE_DIR" ], qb_args = [], ** kwargs )
108
- )
105
+ exit_with (operations .choose (profile_dir = profile_dir , qb_args = [], ** kwargs ))
109
106
110
107
111
108
@main .command ()
112
109
@click .argument ("profile_name" )
113
- @click .pass_context
114
- def edit (ctx , profile_name ):
110
+ @click .pass_obj
111
+ def edit (profile_dir : Path , profile_name ):
115
112
"""Edit a profile's config.py."""
116
- profile = Profile (profile_name , ctx . obj [ "PROFILE_DIR" ] )
113
+ profile = Profile (profile_name , profile_dir )
117
114
if not profile .exists ():
118
115
error (f"profile { profile .name } not found at { profile .root } " )
119
116
exit (1 )
120
117
click .edit (filename = profile .root / "config" / "config.py" )
121
118
122
119
123
120
@main .command (name = "list" )
124
- @click .pass_context
125
- def list_ (ctx ):
121
+ @click .pass_obj
122
+ def list_ (profile_dir : Path ):
126
123
"""List existing profiles."""
127
- for profile in sorted (ctx . obj [ "PROFILE_DIR" ] .iterdir ()):
124
+ for profile in sorted (profile_dir .iterdir ()):
128
125
print (profile .name )
129
126
130
127
@@ -162,7 +159,3 @@ def session_info(
162
159
163
160
def exit_with (result : bool ):
164
161
exit (0 if result else 1 )
165
-
166
-
167
- if __name__ == "__main__" :
168
- main (obj = {})
0 commit comments