2525@click .pass_context
2626def main (ctx , profile_dir : Path ) -> None :
2727 # TODO version
28- ctx .ensure_object (dict )
29- ctx .obj ["PROFILE_DIR" ] = profile_dir
28+ ctx .obj = profile_dir
3029
3130
3231@main .command ()
@@ -36,10 +35,10 @@ def main(ctx, profile_dir: Path) -> None:
3635@click .option ("--overwrite" , is_flag = True )
3736@click .option ("-l" , "--launch" , is_flag = True )
3837@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 ):
4140 """Create a new profile."""
42- profile = Profile (profile_name , ctx . obj [ "PROFILE_DIR" ] )
41+ profile = Profile (profile_name , profile_dir )
4342 then_launch (profiles .new_profile , profile , ** kwargs )
4443
4544
@@ -50,9 +49,9 @@ def new(ctx, profile_name: str, **kwargs):
5049@click .option ("--overwrite" , is_flag = True )
5150@click .option ("-l" , "--launch" , is_flag = True )
5251@click .option ("-f" , "--foreground" , is_flag = True )
53- @click .pass_context
52+ @click .pass_obj
5453def from_session (
55- ctx ,
54+ profile_dir : Path ,
5655 session : str ,
5756 profile_name : Optional [str ],
5857 ** kwargs ,
@@ -61,30 +60,30 @@ def from_session(
6160 SESSION may be the name of a session in the global qutebrowser profile
6261 or a path to a session yaml file.
6362 """
64- profile , session_path = session_info (session , profile_name , ctx . obj [ "PROFILE_DIR" ] )
63+ profile , session_path = session_info (session , profile_name , profile_dir )
6564 then_launch (operations .from_session , profile , session_path = session_path , ** kwargs )
6665
6766
6867@main .command ()
6968@click .argument ("profile_name" )
70- @click .pass_context
69+ @click .pass_obj
7170def desktop (
72- ctx ,
71+ profile_dir : Path ,
7372 profile_name : str ,
7473):
7574 """Create a desktop file for an existing profile."""
76- profile = Profile (profile_name , ctx . obj [ "PROFILE_DIR" ] )
75+ profile = Profile (profile_name , profile_dir )
7776 exit_with (operations .desktop (profile ))
7877
7978
8079@main .command ()
8180@click .argument ("profile_name" )
8281@click .option ("-c" , "--create" , is_flag = True )
8382@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 ):
8685 """Launch qutebrowser with a specific profile."""
87- profile = Profile (profile_name , ctx . obj [ "PROFILE_DIR" ] )
86+ profile = Profile (profile_name , profile_dir )
8887 # TODO qb args
8988 exit_with (operations .launch (profile , qb_args = [], ** kwargs ))
9089
@@ -97,34 +96,32 @@ def launch(ctx, profile_name: str, **kwargs):
9796 help = f"A dmenu-compatible command or one of the following supported menus: { ', ' .join (sorted (SUPPORTED_MENUS ))} " ,
9897)
9998@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 ):
102101 """Choose a profile to launch.
103102 Support is built in for many X and Wayland launchers, as well as applescript dialogs.
104103 """
105104 # 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 ))
109106
110107
111108@main .command ()
112109@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 ):
115112 """Edit a profile's config.py."""
116- profile = Profile (profile_name , ctx . obj [ "PROFILE_DIR" ] )
113+ profile = Profile (profile_name , profile_dir )
117114 if not profile .exists ():
118115 error (f"profile { profile .name } not found at { profile .root } " )
119116 exit (1 )
120117 click .edit (filename = profile .root / "config" / "config.py" )
121118
122119
123120@main .command (name = "list" )
124- @click .pass_context
125- def list_ (ctx ):
121+ @click .pass_obj
122+ def list_ (profile_dir : Path ):
126123 """List existing profiles."""
127- for profile in sorted (ctx . obj [ "PROFILE_DIR" ] .iterdir ()):
124+ for profile in sorted (profile_dir .iterdir ()):
128125 print (profile .name )
129126
130127
@@ -162,7 +159,3 @@ def session_info(
162159
163160def exit_with (result : bool ):
164161 exit (0 if result else 1 )
165-
166-
167- if __name__ == "__main__" :
168- main (obj = {})
0 commit comments