3232from blueapi .config import (
3333 ApplicationConfig ,
3434 ConfigLoader ,
35- StompConfig ,
3635)
3736from blueapi .core import OTLP_EXPORT_ENABLED , DataEvent
3837from blueapi .log import set_up_logging
4443from .updates import CliEventRenderer
4544
4645
47- @click .group (
48- invoke_without_command = True , context_settings = {"auto_envvar_prefix" : "BLUEAPI" }
49- )
50- @click .version_option (version = __version__ , prog_name = "blueapi" )
51- @click .option (
52- "-c" , "--config" , type = Path , help = "Path to configuration YAML file" , multiple = True
53- )
54- @click .pass_context
55- def main (ctx : click .Context , config : Path | None | tuple [Path , ...]) -> None :
56- # if no command is supplied, run with the options passed
57-
58- # Set umask to DLS standard
59- os .umask (stat .S_IWOTH )
60-
46+ def _load_config (ctx : click .Context , config : Path | None | tuple [Path , ...]) -> None :
6147 config_loader = ConfigLoader (ApplicationConfig )
48+
6249 if config is not None :
6350 configs = (config ,) if isinstance (config , Path ) else config
6451 for path in configs :
@@ -74,6 +61,18 @@ def main(ctx: click.Context, config: Path | None | tuple[Path, ...]) -> None:
7461
7562 ctx .obj ["config" ] = loaded_config
7663
64+
65+ @click .group (
66+ invoke_without_command = True , context_settings = {"auto_envvar_prefix" : "BLUEAPI" }
67+ )
68+ @click .version_option (version = __version__ , prog_name = "blueapi" )
69+ @click .pass_context
70+ def main (ctx : click .Context ) -> None :
71+ # if no command is supplied, run with the options passed
72+
73+ # Set umask to DLS standard
74+ os .umask (stat .S_IWOTH )
75+
7776 if ctx .invoked_subcommand is None :
7877 print ("Please invoke subcommand!" )
7978
@@ -135,10 +134,14 @@ def config_schema(output: Path | None = None, update: bool = False) -> None:
135134
136135
137136@main .command (name = "serve" )
138- @click .pass_obj
139- def start_application (obj : dict ):
137+ @click .option (
138+ "-c" , "--config" , type = Path , help = "Path to configuration YAML file" , multiple = True
139+ )
140+ @click .pass_context
141+ def start_application (ctx : click .Context , config : Path | None | tuple [Path , ...]):
140142 """Run a worker that accepts plans to run"""
141- config : ApplicationConfig = obj ["config" ]
143+ _load_config (ctx , config )
144+ loaded_config : ApplicationConfig = ctx .obj ["config" ]
142145
143146 """Only import the service functions when starting the service or generating
144147 the schema, not the controller as a new FastAPI app will be started each time.
@@ -150,7 +153,7 @@ def start_application(obj: dict):
150153 observability context.
151154 """
152155 setup_tracing ("BlueAPI" , OTLP_EXPORT_ENABLED )
153- start (config )
156+ start (loaded_config )
154157
155158
156159@main .group ()
@@ -180,17 +183,17 @@ def controller(
180183 return
181184
182185 ctx .ensure_object (dict )
186+ ctx .obj ["fmt" ] = OutputFormat (output )
187+
188+ _load_config (ctx , None )
183189 config : ApplicationConfig = ctx .obj ["config" ]
184190
185191 if url is not None :
186192 config .api .url = HttpUrl (url )
187193
188- ctx . obj [ "fmt" ] = OutputFormat ( output )
189- ctx . obj [ "client" ] = BlueapiClient . from_config ( config )
194+ tmp_client = BlueapiClient . from_config ( config )
195+ config . stomp = tmp_client . get_stomp_config ( )
190196
191- client : BlueapiClient = ctx .obj ["client" ]
192- stomp_config : StompConfig = client .get_stomp_config ()
193- config .stomp = stomp_config
194197 ctx .obj ["client" ] = BlueapiClient .from_config (config )
195198
196199
0 commit comments